本文整理汇总了PHP中Phar::getStub方法的典型用法代码示例。如果您正苦于以下问题:PHP Phar::getStub方法的具体用法?PHP Phar::getStub怎么用?PHP Phar::getStub使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phar
的用法示例。
在下文中一共展示了Phar::getStub方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testExecuteStub
public function testExecuteStub()
{
$this->checkReadonly();
$content = <<<STUB
<?php
Phar::mapPhar();
__HALT_COMPILER(); ?>
STUB;
$path = $this->buildSource();
file_put_contents($path . '/stub.php', $content);
$plugin = $this->getPlugin(array('stub' => 'stub.php'));
$plugin->getPHPCI()->buildPath = $path;
$this->assertTrue($plugin->execute());
$this->assertFileExists($path . '/build.phar');
$phar = new PHPPhar($path . '/build.phar');
$this->assertEquals($content, trim($phar->getStub()));
// + trim because PHP adds newline char
}
示例2: dirname
$pname = 'phar://' . $fname;
$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar.gz';
$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.tar';
$stub = '<?php echo "first stub\\n"; __HALT_COMPILER(); ?>';
$file = $stub;
$files = array();
$files['a'] = 'a';
$files['b'] = 'b';
$files['c'] = 'c';
include 'files/phar_test.inc';
$phar = new Phar($fname);
var_dump($phar->isFileFormat(Phar::TAR));
var_dump($phar->isCompressed());
var_dump($phar->getStub());
$phar = $phar->convertToExecutable(Phar::TAR, Phar::GZ);
var_dump($phar->isFileFormat(Phar::TAR));
var_dump($phar->isCompressed());
var_dump($phar->getStub());
copy($fname2, $fname3);
$phar = new Phar($fname3);
var_dump($phar->isFileFormat(Phar::TAR));
var_dump($phar->isCompressed() == Phar::GZ);
var_dump($phar->getStub());
?>
===DONE===
<?php
error_reporting(0);
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar.gz');
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar');
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.tar');
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php');
示例3: array
$stub = '<?php echo "first stub\\n"; __HALT_COMPILER(); ?>';
$file = $stub;
$files = array();
$files['a'] = 'a';
$files['b'] = 'b';
$files['c'] = 'c';
include 'files/phar_test.inc';
$phar = new Phar($fname);
var_dump($stub);
var_dump($phar->getStub());
var_dump($phar->getStub() == $stub);
$stub = '<?php echo "second stub\\n"; __HALT_COMPILER(); ?>';
$sexp = $stub . "\r\n";
$phar->setStub($stub);
var_dump($phar->getStub());
var_dump($phar->getStub() == $stub);
var_dump($phar->getStub() == $sexp);
$phar->stopBuffering();
var_dump($phar->getStub());
var_dump($phar->getStub() == $stub);
var_dump($phar->getStub() == $sexp);
$phar = new Phar($fname);
var_dump($phar->getStub() == $stub);
var_dump($phar->getStub() == $sexp);
?>
===DONE===
<?php
error_reporting(0);
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php');
__halt_compiler();
?>
示例4: Phar
<?php
$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar', 0, 'brandnewphar.phar');
//var_dump($p->getStub());
var_dump($p->isBuffering());
$p->startBuffering();
var_dump($p->isBuffering());
$p['a.php'] = '<?php var_dump("Hello");';
$p->setStub('<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
include 'phar://brandnewphar.phar/a.php';
var_dump($p->getStub());
$p['b.php'] = '<?php var_dump("World");';
$p->setStub('<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER();');
include 'phar://brandnewphar.phar/b.php';
var_dump($p->getStub());
$p->stopBuffering();
echo "===COMMIT===\n";
var_dump($p->isBuffering());
include 'phar://brandnewphar.phar/a.php';
include 'phar://brandnewphar.phar/b.php';
var_dump($p->getStub());
?>
===DONE===
<?php
unlink(dirname(__FILE__) . '/brandnewphar.phar');
示例5: Phar
<?php
chdir(dirname(__FILE__));
try {
$p = new Phar('brandnewphar.phar');
$p['file1.txt'] = 'hi';
var_dump(strlen($p->getStub()));
$p->setStub("<?php\nfunction __autoload(\$class)\n{\n include 'phar://' . str_replace('_', '/', \$class);\n}\nPhar::mapPhar('brandnewphar.phar');\ninclude 'phar://brandnewphar.phar/startup.php';\n__HALT_COMPILER();\n?>");
var_dump($p->getStub());
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
?>
===DONE===
<?php
unlink(dirname(__FILE__) . '/brandnewphar.phar');
示例6: dirname
<?php
$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip.php';
$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
$pname = 'phar://' . $fname;
$pname2 = 'phar://' . $fname2;
$p = new Phar($pname2);
$p->setStub('<?php echo "first stub\\n"; __HALT_COMPILER(); ?>');
$p['a'] = 'a';
$p['b'] = 'b';
$p['c'] = 'c';
copy($fname2, $fname);
$phar = new Phar($fname);
echo $phar->getStub();
$file = '<?php echo "second stub\\n"; __HALT_COMPILER(); ?>';
//// 2
$phar->setStub($file);
echo $phar->getStub();
$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phartmp.php';
$file = '<?php echo "third stub\\n"; __HALT_COMPILER(); ?>';
$fp = fopen($fname3, 'wb');
fwrite($fp, $file);
fclose($fp);
$fp = fopen($fname3, 'rb');
//// 3
$phar->setStub($fp);
fclose($fp);
echo $phar->getStub();
$fp = fopen($fname3, 'ab');
fwrite($fp, 'booya');
fclose($fp);
示例7: strlen
<?php
$p = new Phar(__FILE__);
var_dump($p->getStub());
$p2 = new Phar(__FILE__);
$p->setDefaultStub();
echo strlen($p2->getStub()), "\n";
echo "ok\n";
__halt_compiler(); ?>
6test.txtШ∆тH©јПE∂<?php __HALT_COMPILER();Кj?НѕcЂxH¢Вы*Ф}»!У5GBMB
示例8: dirname
<?php
$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar';
$phar = new Phar($fname);
$phar['a.txt'] = 'some text';
$phar->stopBuffering();
var_dump($phar->isFileFormat(Phar::TAR));
var_dump(strlen($phar->getStub()));
$phar = $phar->convertToExecutable(Phar::TAR);
var_dump($phar->isFileFormat(Phar::TAR));
var_dump($phar->getStub());
$phar['a'] = 'hi there';
$phar = $phar->convertToExecutable(Phar::PHAR, Phar::GZ);
var_dump($phar->isFileFormat(Phar::PHAR));
var_dump($phar->isCompressed());
var_dump(strlen($phar->getStub()));
copy($fname . '.gz', $fname2);
$phar = new Phar($fname2);
var_dump($phar->isFileFormat(Phar::PHAR));
var_dump($phar->isCompressed() == Phar::GZ);
var_dump(strlen($phar->getStub()));
?>
===DONE===
示例9: Phar
<?php
$p = new Phar(__FILE__);
var_dump($p->getStub());
$p2 = new Phar(__FILE__);
$a = fopen("phar://" . __FILE__ . "/test.txt", "r");
$p->setStub($a);
echo $p2->getStub(), "\n";
echo "ok\n";
__halt_compiler(); ?>
6test.txt+√тH©јПE∂<?php __HALT_COMPILER();ГЄљі]су+ЏЈWйТьцcGBMB
示例10: Phar
$phar = new Phar($outputFile, 0, 'mongrate.phar');
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
$phar->addFile('vendor/autoload.php');
$phar->addFile('vendor/composer/autoload_namespaces.php');
$phar->addFile('vendor/composer/autoload_classmap.php');
$phar->addFile('vendor/composer/autoload_real.php');
$finder = new Finder();
$finder->files()->ignoreVCS(true)->name('*.php')->exclude('Tests')->notName('get-version.php')->in('src')->in('vendor/composer')->in('vendor/doctrine')->in('vendor/symfony/class-loader')->in('vendor/symfony/console')->in('vendor/symfony/yaml');
foreach ($finder as $file) {
// Stripping whitespace from the file reduces the Phar file size by over 50% on first test
// (from 1.5 MB to 679 KB).
$minifiedPhp = php_strip_whitespace((string) $file->getPathName());
$phar->addFromString($file->getPathName(), $minifiedPhp);
}
$finder = new Finder();
$finder->files()->in('resources/migration-template/');
foreach ($finder as $file) {
$phar->addFile($file->getPathName());
}
$version = (require_once 'src/get-version.php');
$phar->addFromString('index.php', '
<?php
define("MONGRATE_VERSION", "' . $version . '");
require_once "src/create-application.php";
$app->run();
');
$phar->setStub("#!/usr/bin/env php \n" . $phar->getStub());
$phar->stopBuffering();
// Make the file executable so it can be run without having to type `php` before it.
chmod($outputFile, 0555);