本文整理汇总了PHP中Phar::buildFromDirectory方法的典型用法代码示例。如果您正苦于以下问题:PHP Phar::buildFromDirectory方法的具体用法?PHP Phar::buildFromDirectory怎么用?PHP Phar::buildFromDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phar
的用法示例。
在下文中一共展示了Phar::buildFromDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Execute the task
*
* @throws Exception
* @return void
*/
public function execute()
{
$target = $this->getOption('target');
$sourceDirectory = $this->getOption('sourceDirectory');
$stubFile = $this->getOption('stubFile');
if (!extension_loaded('phar')) {
throw new \Exception('Phar extension not loaded');
}
if (!is_dir($sourceDirectory)) {
throw new \Exception('Source directory not found: ' . $sourceDirectory);
}
// check to see if we can create phar files
$readOnly = ini_get('phar.readonly');
if ($readOnly != 1) {
$phar = new \Phar($target, 0, basename($target));
$phar->startBuffering();
$phar->buildFromDirectory($sourceDirectory);
$stub = $phar->createDefaultStub();
$phar->setStub($stub);
$phar->stopBuffering();
//$phar->compress(Phar::GZ);
} else {
throw new \Exception('Cannot create phar! (read-only enabled)');
}
}
示例2: build_pheanstalk_phar
function build_pheanstalk_phar()
{
printf("- Building %s from %s\n", PHAR_FILENAME, BASE_DIR);
$phar = new Phar(PHAR_FULLPATH);
$phar->buildFromDirectory(BASE_DIR);
$phar->setStub($phar->createDefaultStub("vendor/autoload.php"));
}
示例3: testItExtractsIconFromPhar
public function testItExtractsIconFromPhar()
{
$key = uniqid();
$iconContent = $key;
$rootPackage = dirname(dirname(__FILE__));
$iconRelativePath = 'Resources/notification/icon-' . $key . '.png';
$testDir = sys_get_temp_dir() . '/test-jolinotif';
$pharPath = $testDir . '/notification-extract-icon-' . $key . '.phar';
$extractedIconPath = sys_get_temp_dir() . '/jolinotif/' . $iconRelativePath;
if (!is_dir($testDir)) {
mkdir($testDir);
}
$bootstrap = <<<'PHAR_BOOTSTRAP'
<?php
require __DIR__.'/vendor/autoload.php';
$iconPath = THE_ICON;
$notification = new \Joli\JoliNotif\Notification();
$notification->setBody('My notification');
$notification->setIcon(__DIR__.$iconPath);
PHAR_BOOTSTRAP;
$phar = new \Phar($pharPath);
$phar->buildFromDirectory($rootPackage, '#(src|tests/fixtures|vendor/composer)#');
$phar->addFromString('bootstrap.php', str_replace('THE_ICON', '\'/' . $iconRelativePath . '\'', $bootstrap));
$phar->addFromString($iconRelativePath, $iconContent);
$phar->addFile('vendor/autoload.php');
$phar->setStub($phar->createDefaultStub('bootstrap.php'));
$this->assertTrue(is_file($pharPath));
exec('php ' . $pharPath);
$this->assertTrue(is_file($extractedIconPath));
$this->assertSame($iconContent, file_get_contents($extractedIconPath));
}
示例4: doExecute
/**
* Method to run the application routines. Most likely you will want to instantiate a controller
* and execute it, or perform some sort of task directly.
*
* @return void
*
* @since 2.0
*/
protected function doExecute()
{
if ($this->io->getOption('h') || $this->io->getOption('help')) {
$this->help();
return;
}
$dir = $this->io->getOption('d', '../../vaseman.phar');
$file = __DIR__ . '/' . $dir;
if (is_file($file)) {
unlink($file);
}
$this->out('Start generating...');
$phar = new Phar($file);
$phar->setStub(<<<PHP
#!/usr/bin/env php
<?php
Phar::mapPhar('vaseman.phar');
require 'phar://vaseman.phar/bin/vaseman'; __HALT_COMPILER();
PHP
);
$phar->buildFromDirectory(__DIR__ . '/..');
$phar->stopBuffering();
$this->out('Phar generated: ' . $file)->out();
}
示例5: _build
protected static function _build($conf)
{
$pathToPhar = $conf['path_to_phar'];
$pharName = $conf['phar_name'];
$srcPath = $conf['src_path'];
$initModule = $conf['init_module'];
$setup = $conf['setup'];
$file = $pathToPhar . '/' . $pharName;
if ($conf['delete_old_phar_onbuild'] && \file_exists($file)) {
\unlink($file);
}
$falias = $pharName;
$mapPhar = $pharName;
$phar = new \Phar($file, 0, $falias);
$phar->startBuffering();
$dir = $phar->buildFromDirectory($srcPath);
$stub = '<?php ' . "\\Phar::mapPhar('{$falias}'); " . 'include ' . "'phar://{$falias}/{$initModule}'; " . "{$setup}" . '__HALT_COMPILER();';
$phar->setStub($stub);
//
//
if (isset($conf['compress_pkg']) && $conf['compress_pkg'] == 'GZ') {
$phar->compressFiles(\Phar::GZ);
}
//
//
$phar->stopBuffering();
}
示例6: build_phar
function build_phar()
{
$phar = new Phar('build/bugsnag.phar');
$phar->buildFromDirectory(dirname(__FILE__) . '/src', '/\\.php$/');
$phar->compressFiles(Phar::GZ);
$phar->stopBuffering();
$phar->setStub($phar->createDefaultStub('Bugsnag/Autoload.php'));
}
示例7: create
static function create($phar_file, $php_dir, $default_stub)
{
$phar = new \Phar($phar_file);
$phar->buildFromDirectory($php_dir, '/\\.php$/');
$phar->compressFiles(\Phar::GZ);
$phar->stopBuffering();
$phar->setStub($phar->createDefaultStub($default_stub));
}
示例8: build_pheanstalk_phar
function build_pheanstalk_phar()
{
$classDir = BASE_DIR . '/classes';
printf("- Building %s from %s\n", PHAR_FILENAME, $classDir);
$phar = new Phar(PHAR_PATH);
$phar->buildFromDirectory($classDir);
$phar->setStub(pheanstalk_phar_stub());
}
示例9: setUp
/**
* Prepare environment before test.
*/
protected function setUp()
{
//Build phar archives
$this->srcPharPath = dirname(dirname(dirname(__FILE__))) . '/Support/src/';
//namespace
$this->pharFileNamespace = dirname(dirname(dirname(__FILE__))) . '/Support/pharFileNamespace.phar';
if (0 == ini_get('phar.readonly') && !file_exists($this->pharFileNamespace)) {
$phar = new \Phar($this->pharFileNamespace, 0, 'pharFileNamespace.phar');
$phar->buildFromDirectory($this->srcPharPath . '/NamespaceLoader/');
}
parent::setUp();
}
示例10: setUp
/**
* Create the PHAR multiple.phar for the test if this file does not exist.
*/
protected function setUp()
{
$multiplePharPath = TK_STATES_TEST_PATH . DIRECTORY_SEPARATOR . 'Support' . DIRECTORY_SEPARATOR . 'multiple.phar';
if (!file_exists($multiplePharPath)) {
//Compute Path for this Phar
$multiplePath = TK_STATES_TEST_PATH . DIRECTORY_SEPARATOR . 'Support' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Multiple';
//Build phat
$phar = new \Phar($multiplePharPath, 0, 'multiple.phar');
$phar->buildFromDirectory($multiplePath);
}
parent::setUp();
}
示例11: makePhar
static function makePhar(array $dt)
{
//retornando com erro se o array estiver vazio
if (count($dt) <= 0) {
return false;
}
//aumentando a memoria e o tempo de execução - pode ser muito significante em sistemas lentos e diretórios muito grandes
ini_set('memory_limit', '30M');
ini_set('max_execution_time', 180);
//Array com os dados da execução
$ok = array();
//lendo e executando as conversões indicadas
foreach ($dt as $k => $lote) {
$stub = '<?php
Phar::interceptFileFuncs();
Phar::mungServer(array(\'REQUEST_URI\', \'PHP_SELF\', \'SCRIPT_NAME\', \'SCRIPT_FILENAME\'));
Phar::webPhar(\'\', \'\', \'404.php\');
__HALT_COMPILER();';
if (is_dir($lote['o'])) {
//criando arquivo PHAR
$phar = new \Phar($lote['d']);
//pegando o diretório (e sub-diretórios) e arquivos contidos
$phar->buildFromDirectory($lote['o']);
//criando o cabeçalho Stub
$phar->setStub($stub);
//carregando a assinatura
if (is_file($lote['o'])) {
$phar->setSignatureAlgorithm(\Phar::MD5, file_get_contents($lote['o']));
}
//comprimindo os dados (exceto o Stub)
$compactar = false;
if (isset($lote['z'])) {
$compactar = true;
if (\Phar::canCompress(\Phar::GZ)) {
$phar->compressFiles(\Phar::GZ);
} elseif (\Phar::canCompress(\Phar::BZ2)) {
$phar->compressFiles(\Phar::BZ2);
}
}
//adicionando os dados de saída
$ok[$k] = array('o' => $lote['o'], 'd' => $lote['d'], 'z' => $compactar, 'i' => $lote['i']);
} else {
$ok[$k] = array('e' => 'O diretório "' . $lote['o'] . '" não existe!');
}
}
if (count($ok) == 0) {
return false;
}
return $ok;
}
示例12: realpath
function __construct($pharName)
{
echo "<pre>";
$buildRoot = realpath(Ruth::getDOCUMENT_ROOT() . "/../build");
$srcRoot = realpath(Ruth::getDOCUMENT_ROOT());
echo "Building {$pharName}.phar to " . $buildRoot . "\n";
echo "Source: {$srcRoot} \n";
echo "Have you cleaned up the path yet ?";
//clean up things
$phar = new Phar($buildRoot . "/" . $pharName . ".phar", FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, $pharName . ".phar");
$phar["index.php"] = file_get_contents($srcRoot . "/index.php");
$phar->buildFromDirectory($srcRoot);
$phar->setStub('<?php Phar::webPhar(); __HALT_COMPILER();');
echo "<pre>";
}
示例13: convertVendorsToPhar
public static function convertVendorsToPhar(Event $event)
{
$vendorDir = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'vendor';
$phars = [];
echo "Converting vendor package dirs to phar...\n";
foreach (new \DirectoryIterator($vendorDir) as $dir) {
if (in_array($dir->getFilename(), ['..', '.', 'composer']) || !$dir->isDir()) {
continue;
}
foreach (new \DirectoryIterator($dir->getRealPath()) as $subDir) {
if (in_array($subDir->getFilename(), ['..', '.']) || !$subDir->isDir()) {
continue;
}
echo "... " . $dir->getFilename() . '/' . $subDir->getFilename() . "\n";
$fName = $subDir->getRealPath() . '.phar';
$fNameTmp = $fName . '.tmp';
$phar = new \Phar($fNameTmp);
$phar->buildFromDirectory($subDir->getRealPath(), '#\\.(?!git)#');
if (\Phar::canCompress(\Phar::GZ)) {
$phar->compressFiles(\Phar::GZ);
} else {
if (\Phar::canCompress(\Phar::BZ2)) {
$phar->compressFiles(\Phar::BZ2);
}
}
if (file_exists($fName)) {
unlink($fName);
}
unset($phar);
rename($fNameTmp, $fName);
//delDirTree($subDir->getRealPath());
$phars[$dir->getFilename() . '/' . $subDir->getFilename()] = str_replace(DIRECTORY_SEPARATOR, '/', str_replace($vendorDir, '', $fName));
}
}
echo "\nConverting autoload files: \n";
$autoloadFiles = ['composer/autoload_classmap.php', 'composer/autoload_files.php', 'composer/autoload_namespaces.php', 'composer/autoload_psr4.php'];
foreach ($autoloadFiles as $file) {
echo $file . "\n";
$filePath = $vendorDir . DIRECTORY_SEPARATOR . $file;
$content = file_get_contents($filePath);
$content = preg_replace('#(?<!\'phar://\' . )\\$vendorDir\\s+.\\s+\'(/[-\\w\\d_]+/[-\\w\\d_]+)#', '\'phar://\' . $vendorDir . \'$1.phar', $content);
if ($content) {
file_put_contents($filePath, $content);
}
}
echo "\nComplete!\n";
}
示例14: build
public function build()
{
$this->prepareTemp();
/* Dateien ins Temp-Verzeichnis kopieren */
$class2path = array();
$relDir = $this->classPath->up();
// wir wollen ja den Namespace als erstes Verzeichnis haben
foreach ($this->getClassFiles() as $file) {
$class = $this->inferClassName($file);
// $class2path[ $class ] = $fileURL;
$class2path[ltrim($class, '\\')] = $url = $file->getURL($relDir);
// statt hier Code::mapClassToFile() zu machen nehmen wir die url
$targetFile = File::createFromURL($url, $this->tempSrc);
$targetFile->getDirectory()->create();
$this->log(str_pad('Add: ' . $url, 80, ' ', STR_PAD_RIGHT) . " [" . $class . "]", 2);
$file->copy($targetFile);
}
foreach ($this->additionalFiles as $list) {
list($file, $fileInPhar) = $list;
$targetFile = new File($this->tempSrc . $fileInPhar);
$targetFile->getDirectory()->create();
$this->log('Add: ' . $fileInPhar);
$file->copy($targetFile);
}
/* Bootstrapping */
$bootstrapCode = $this->getBootstrapCode($class2path);
$bootstrapFile = new File($this->tempSrc, 'index.php');
$bootstrapFile->writeContents($bootstrapCode);
/* Build */
try {
$tmp = File::createTemporary();
$tmp->setExtension('phar.gz');
$this->phar = new PHPPhar((string) $tmp);
$this->phar->compress(PHPPHAR::GZ);
$this->phar->startBuffering();
$this->phar->buildFromDirectory($this->tempSrc);
$this->phar->stopBuffering();
$this->tempSrc->delete();
$this->out->delete();
$tmp->copy($this->out);
} catch (\Exception $e) {
$this->tempSrc->delete();
throw $e;
}
}
示例15: array
<?php
$defaults = array('cli' => 'src/cli.php', 'web' => 'src/web.php', 'bin' => 'application.phar');
$temp_file = 'application.phar';
$options = getopt('', array('cli::', 'web::', 'bin::'));
$options = array_merge($defaults, $options);
@unlink($options['bin']);
@unlink($temp_file);
$phar = new Phar($temp_file);
$phar->buildFromDirectory(__DIR__, '/^((?!\\.git).)*$/');
$defaultStub = $phar->createDefaultStub($options['cli'], $options['web']);
$defaultStub = "#!/usr/bin/env php\n" . $defaultStub;
$phar->setStub($defaultStub);
unset($phar);
chmod($temp_file, 0755);
rename($temp_file, $options['bin']);