本文整理汇总了PHP中Phar::setDefaultStub方法的典型用法代码示例。如果您正苦于以下问题:PHP Phar::setDefaultStub方法的具体用法?PHP Phar::setDefaultStub怎么用?PHP Phar::setDefaultStub使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phar
的用法示例。
在下文中一共展示了Phar::setDefaultStub方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testReading
/**
* Test that the reading is successful.
*
* @return void
*
* @dataProvider testReadingFlagsProvider
*/
public function testReading($compression, $signatureName, $signatureFlag)
{
$pharfile = $this->getTempFile('temp.phar');
$phar = new \Phar($pharfile, 0, 'temp.phar');
$phar->startBuffering();
$phar->addFromString('/bin/script', $fileData = <<<EOF
#!/usr/bin/php
<?php
echo 'hello world';
EOF
);
$phar->setDefaultStub('/bin/script', '/web/index');
$phar->stopBuffering();
$phar->setSignatureAlgorithm($signatureFlag);
if ($compression !== \Phar::NONE) {
$phar->compressFiles($compression);
}
unset($phar);
$reader = new PharReader();
$phar = $reader->load($pharfile);
$this->assertEquals('temp.phar', $phar->getAlias());
$this->assertTrue($phar->isSigned());
$this->assertEquals($signatureName, $phar->getSignatureAlgorithm());
$files = $phar->getFiles();
$this->assertEquals('bin/script', $files[0]->getFilename());
$this->assertEquals($fileData, $files[0]->getContent());
}
示例2: compile
public function compile()
{
if (file_exists('symfony.phar')) {
unlink('symfony.phar');
}
$phar = new \Phar('symfony.phar', 0, 'Symfony');
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
// Files
foreach ($this->getFiles() as $file) {
$path = str_replace(__DIR__ . '/', '', $file);
if (false !== strpos($file, '.php')) {
$content = Kernel::stripComments(file_get_contents($file));
} else {
$content = file_get_contents($file);
}
$phar->addFromString($path, $content);
}
// Stubs
$phar['_cli_stub.php'] = $this->getCliStub();
$phar['_web_stub.php'] = $this->getWebStub();
$phar->setDefaultStub('_cli_stub.php', '_web_stub.php');
$phar->stopBuffering();
//$phar->compressFiles(\Phar::GZ);
unset($phar);
}
示例3: buildModulePhar
function buildModulePhar($name, $format = Phar::PHAR, $compression = Phar::NONE, $executable = true, $fake = false)
{
echo "Building {$name}...\t";
$glob = glob($name.'.*');
if (count($glob) > 0) {
foreach ($glob as $file) {
if (!is_dir($file)) {
unlink($file);
}
}
}
$filename = $name . '.phar';
$phar = new Phar($filename);
if ($fake) {
$phar['Module.php'] = '<?php //no class here';
} else {
$phar['Module.php'] = "<?php \n\nnamespace $name;\n\nclass Module\n{}";
}
if (false === $executable) {
$phar->convertToData($format, $compression);
} else {
$phar->setDefaultStub('Module.php', 'Module.php');
if ($format !== Phar::PHAR || $compression !== Phar::NONE) {
$phar->convertToExecutable($format, $compression);
}
}
if ($format !== Phar::PHAR || $compression !== Phar::NONE) {
unlink($filename);
}
echo "Done!\n";
}
示例4: compile
public function compile($pharFile = 'goutte.phar')
{
if (file_exists($pharFile)) {
unlink($pharFile);
}
$phar = new \Phar($pharFile, 0, 'Goutte');
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
// CLI Component files
foreach ($this->getFiles() as $file) {
$path = str_replace(__DIR__ . '/', '', $file);
$phar->addFromString($path, file_get_contents($file));
}
// Stubs
$phar['_cli_stub.php'] = $this->getCliStub();
$phar['_web_stub.php'] = $this->getWebStub();
$phar->setDefaultStub('_cli_stub.php', '_web_stub.php');
$phar->stopBuffering();
// $phar->compressFiles(\Phar::GZ);
unset($phar);
}
示例5: compile
public function compile($pharFile = 'silex.phar')
{
if (file_exists($pharFile)) {
unlink($pharFile);
}
$phar = new \Phar($pharFile, 0, 'Silex');
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
$finder = new Finder();
$finder->files()->name('*.php')->exclude('tests')->in(__DIR__ . '/..');
foreach ($finder as $file) {
$path = str_replace(realpath(__DIR__ . '/../..') . '/', '', realpath($file));
$content = Kernel::stripComments(file_get_contents($file));
$phar->addFromString($path, $content);
}
// Stubs
$phar['_cli_stub.php'] = $this->getStub();
$phar['_web_stub.php'] = $this->getStub();
$phar->setDefaultStub('_cli_stub.php', '_web_stub.php');
$phar->stopBuffering();
// $phar->compressFiles(\Phar::GZ);
unset($phar);
}
示例6: buildPhar
/**
* Build and configure Phar object.
*
* @return Phar
*/
private function buildPhar()
{
$phar = new Phar($this->destinationFile);
if (!empty($this->stubPath)) {
$phar->setStub(file_get_contents($this->stubPath));
} else {
if (!empty($this->cliStubFile)) {
$cliStubFile = $this->cliStubFile->getPathWithoutBase($this->baseDirectory);
} else {
$cliStubFile = null;
}
if (!empty($this->webStubFile)) {
$webStubFile = $this->webStubFile->getPathWithoutBase($this->baseDirectory);
} else {
$webStubFile = null;
}
$phar->setDefaultStub($cliStubFile, $webStubFile);
}
if ($this->metadata === null) {
$this->createMetaData();
}
if ($metadata = $this->metadata->toArray()) {
$phar->setMetadata($metadata);
}
if (!empty($this->alias)) {
$phar->setAlias($this->alias);
}
return $phar;
}
示例7: dirname
<?php
$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
$phar = new Phar($fname);
$phar['a.php'] = '<php echo "this is a\\n"; ?>';
$phar['b.php'] = '<php echo "this is b\\n"; ?>';
$phar->setDefaultStub();
$phar->stopBuffering();
var_dump($phar->getStub());
echo "============================================================================\n";
echo "============================================================================\n";
$phar->setDefaultStub('my/custom/thingy.php');
$phar->stopBuffering();
var_dump($phar->getStub());
echo "============================================================================\n";
echo "============================================================================\n";
$phar->setDefaultStub('my/custom/thingy.php', 'the/web.php');
$phar->stopBuffering();
var_dump($phar->getStub());
echo "============================================================================\n";
echo "============================================================================\n";
try {
$phar->setDefaultStub(str_repeat('a', 400));
$phar->stopBuffering();
var_dump(strlen($phar->getStub()));
$phar->setDefaultStub(str_repeat('a', 401));
$phar->stopBuffering();
var_dump(strlen($phar->getStub()));
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
示例8: Exception
<?php
set_error_handler(function ($num, $msg, $file, $line) {
throw new Exception($msg, 0, $num, $file, $line);
});
$targetDirPath = __DIR__ . '/target';
if (!file_exists($targetDirPath)) {
mkdir($targetDirPath);
}
$phar = new Phar($targetDirPath . '/lightship.phar', 0, 'lightship.phar');
$phar->buildFromDirectory(__DIR__ . '/src/Lightship/Bin/lightship/');
$phar->setDefaultStub('lightship.php');
示例9: Phar
<?php
## Создание PHAR-архива с заглушкой.
try {
$phar = new Phar('./autopager.phar', 0, 'autopager.phar');
// Для записи директив phar.readonly конфигурационного
// файла php.ini должна быть установлена в 0 или Off
if (Phar::canWrite()) {
// Буферизация записи, ничего не записывается, до
// тех пор, пока не будет вызван метод stopBuffering()
$phar->startBuffering();
// Добавление всех файлов из компонента ISPager
$phar->buildFromIterator(new DirectoryIterator(realpath('../composer/pager/src/ISPager')), '../composer/pager/src');
// Добавляем автозагрузчик в архив
$phar->addFromString('autoloader.php', file_get_contents('autoloader.php'));
// Назначаем автозагрузчик в качестве файла-заглушки
$phar->setDefaultStub('autoloader.php', 'autoloader.php');
// Сохранение результатов на жесткий диск
$phar->stopBuffering();
} else {
echo 'PHAR-архив не может быть бы записан';
}
} catch (Exception $e) {
echo 'Невозможно открыть PHAR-архив: ', $e;
}
示例10: Phar
<?
$sLibraryPath = 'lib/SampleLibrary.phar';
// we will build library in case if it not exist
if (! file_exists($sLibraryPath)) {
ini_set("phar.readonly", 0); // Could be done in php.ini
$oPhar = new Phar($sLibraryPath); // creating new Phar
$oPhar->setDefaultStub('index.php', 'classes/index.php'); // pointing main file which require all classes
$oPhar->buildFromDirectory('classes/'); // creating our library using whole directory
$oPhar->compress(Phar::GZ); // plus - compressing it into gzip
}
// when library already compiled - we will using it
require_once('phar://'.$sLibraryPath.'.gz');
// demonstration of work
$oClass1 = new SampleClass();
echo $oClass1->getAnyContent();
echo '<pre>';
print_r($oClass1);
echo '</pre>';
$oClass2 = new SampleClass2();
echo $oClass2->getAnyContent();
echo $oClass2->getContent2();
echo '<pre>';
print_r($oClass2);
echo '</pre>';
示例11: dirname
<?php
$fname = dirname(__FILE__) . '/tempmanifest2.phar.php';
$pname = 'phar://' . $fname;
$phar = new Phar($fname);
$phar->setDefaultStub();
$phar->setAlias('fred');
$phar['file1.txt'] = 'hi';
$phar['file2.txt'] = 'hi2';
$phar['subdir/ectory/file.txt'] = 'hi3';
$phar->mount($pname . '/mount2', __FILE__);
$phar->addEmptyDir('one/level');
$phar->extractTo(dirname(__FILE__) . '/extract2', 'mount2');
$phar->extractTo(dirname(__FILE__) . '/extract2');
$out = array();
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/extract2', 0x3000), RecursiveIteratorIterator::CHILD_FIRST) as $path => $file) {
$extracted[] = $path;
}
sort($extracted);
foreach ($extracted as $out) {
echo "{$out}\n";
}
?>
===DONE===
<?php
@unlink(dirname(__FILE__) . '/tempmanifest2.phar.php');
$dir = dirname(__FILE__) . '/extract2/';
@unlink($dir . 'file1.txt');
@unlink($dir . 'file2.txt');
@unlink($dir . 'subdir/ectory/file.txt');
@rmdir($dir . 'subdir/ectory');
示例12: Phar
<?php
## Хранение бинарных файлов.
try {
$phar = new Phar('./gallery.phar', 0, 'gallery.phar');
// Для записи директив phar.readonly конфигурационного
// файла php.ini должна быть установлена в 0 или Off
if (Phar::canWrite()) {
// Буферизация записи, ничего не записывается, до
// тех пор, пока не будет вызван метод stopBuffering()
$phar->startBuffering();
// Добавление всех файлов из папки photos
foreach (glob('../composer/photos/*') as $jpg) {
$phar[basename($jpg)] = file_get_contents($jpg);
}
// Назначаем файл-заглушку
$phar['show.php'] = file_get_contents('show.php');
$phar->setDefaultStub('show.php', 'show.php');
// Сохранение результатов на жесткий диск
$phar->stopBuffering();
} else {
echo 'PHAR-архив не может быть бы записан';
}
} catch (Exception $e) {
echo 'Невозможно открыть PHAR-архив: ', $e;
}
示例13: buildPhar
/**
* Build and configure Phar object.
*
* @return Phar
*/
private function buildPhar()
{
$phar = new Phar($this->destinationFile);
$phar->setSignatureAlgorithm($this->signatureAlgorithm);
if (isset($this->stubPath)) {
$phar->setStub(file_get_contents($this->stubPath));
} else {
$phar->setDefaultStub($this->cliStubFile->getPathWithoutBase($this->baseDirectory), $this->webStubFile->getPathWithoutBase($this->baseDirectory));
}
if ($metadata = $this->metadata->toArray()) {
$phar->setMetadata($metadata);
}
if (!empty($this->alias)) {
$phar->setAlias($this->alias);
}
return $phar;
}
示例14: Phar
<?php
$sLibraryPath = '../CompiledPHAR/SecurityCheck_compiled.phar';
if (file_exists($sLibraryPath)) {
@unlink($sLibraryPath);
}
if (file_exists($sLibraryPath . ".gz")) {
@unlink($sLibraryPath . ".gz");
}
if (!file_exists($sLibraryPath)) {
ini_set("phar.readonly", 0);
// Could be done in php.ini
$oPhar = new Phar($sLibraryPath);
// creating new Phar
$oPhar->setDefaultStub('index.php', '../SecurityCheck/index.php');
// pointing main file which require all classes
$oPhar->buildFromDirectory('../SecurityCheck/');
// creating our library using whole directory
$oPhar->compress(Phar::GZ);
// plus - compressing it into gzip
}
示例15: testWriteLoaded
/**
* Test that the writing of a loaded phar results in an equal file.
*
* @return void
*
* @dataProvider testWritingFlagsProvider
*/
public function testWriteLoaded($compression, $signatureFlag)
{
$pharfile = $this->getTempFile('temp.phar');
$phar = new \Phar($pharfile, 0, 'temp.phar');
$phar->startBuffering();
$phar->addFromString('/bin/script', $fileData = <<<EOF
#!/usr/bin/php
<?php
echo 'hello world';
EOF
);
$phar->setDefaultStub('/bin/script', '/web/index');
$phar->stopBuffering();
if (0 !== $signatureFlag) {
$phar->setSignatureAlgorithm($signatureFlag);
}
if ($compression !== \Phar::NONE) {
$phar->compress($compression);
}
unset($phar);
$reader = new PharReader();
$phar = $reader->load($pharfile);
$pharfile2 = $this->getTempFile('temp.phar');
$writer = new PharWriter();
$writer->save($phar, $pharfile2);
unset($writer);
$this->assertFileEquals($pharfile, $pharfile2);
}