当前位置: 首页>>代码示例>>PHP>>正文


PHP Phar::buildFromDirectory方法代码示例

本文整理汇总了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)');
     }
 }
开发者ID:robertbasic,项目名称:usher,代码行数:31,代码来源:Phar.php

示例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"));
}
开发者ID:xiaoziwuzui,项目名称:gdby_github_repo,代码行数:7,代码来源:build_phar.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));
    }
开发者ID:kjmtrue,项目名称:JoliNotif,代码行数:33,代码来源:NotificationTest.php

示例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();
    }
开发者ID:bgao-ca,项目名称:vaseman,代码行数:34,代码来源:build.php

示例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();
 }
开发者ID:swwwfactory,项目名称:entry8,代码行数:27,代码来源:utils.php

示例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'));
}
开发者ID:ayurmedia,项目名称:faveo-helpdesk,代码行数:8,代码来源:pharbuilder.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));
 }
开发者ID:jasonshaw,项目名称:framework-1,代码行数:8,代码来源:Phar.php

示例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());
}
开发者ID:astronautyan,项目名称:O2OMobile_PHP,代码行数:8,代码来源:build_phar.php

示例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();
 }
开发者ID:rakesh-mohanta,项目名称:states,代码行数:15,代码来源:LoaderComposerTest.php

示例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();
 }
开发者ID:unialteri,项目名称:states,代码行数:15,代码来源:MultipleTest.php

示例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;
    }
开发者ID:elandio,项目名称:pizza-10,代码行数:50,代码来源:file.php

示例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>";
 }
开发者ID:richardkeep,项目名称:tina4stack,代码行数:15,代码来源:Phoebe.php

示例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";
 }
开发者ID:scottleedavis,项目名称:hackazon,代码行数:47,代码来源:ComposerPharMaker.php

示例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;
     }
 }
开发者ID:pscheit,项目名称:psc-cms,代码行数:45,代码来源:Phar.php

示例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']);
开发者ID:webreactor,项目名称:db-migration,代码行数:16,代码来源:build-phar.php


注:本文中的Phar::buildFromDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。