當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Phar::addFromString方法代碼示例

本文整理匯總了PHP中Phar::addFromString方法的典型用法代碼示例。如果您正苦於以下問題:PHP Phar::addFromString方法的具體用法?PHP Phar::addFromString怎麽用?PHP Phar::addFromString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Phar的用法示例。


在下文中一共展示了Phar::addFromString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: compile

 public function compile($pharFile, $name = 'foo-app', array $files = array(), array $directories = array(), $stub_file, $base_path, $name_pattern = '*.php', $strip = TRUE)
 {
     if (file_exists($pharFile)) {
         unlink($pharFile);
     }
     $phar = new \Phar($pharFile, 0, $name);
     // The signature is automatically set unless we decide to compress. In that
     // case we have to manually set it. Setting to the default just in case.
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     // CLI Component files
     $iterator = Finder::create()->files()->name($name_pattern)->in($directories);
     // We need to set the adapter to use the PhpAdapter because we are working
     // with Phar files and the higher priority ones by default in symfony can
     // run into issues.
     //$iterator->removeAdapters();
     //$iterator->addAdapter(new PhpAdapter());
     $files = array_merge($files, iterator_to_array($iterator));
     foreach ($files as $file) {
         $path = str_replace($base_path . '/', '', $file);
         if ($strip) {
             $phar->addFromString($path, php_strip_whitespace($file));
         } else {
             $phar->addFromString($path, file_get_contents($file));
         }
     }
     $phar->setStub(file_get_contents($stub_file));
     $phar->stopBuffering();
     // Not all systems support compressed Phars. For now disabling.
     // $phar->compressFiles(\Phar::GZ);
     chmod($pharFile, 0755);
     unset($phar);
 }
開發者ID:masterminds,項目名稱:fortissimo-cli,代碼行數:33,代碼來源:Compiler.php

示例3: addFile

/**
 * Add a file in phar removing whitespaces from the file
 *
 * @param Phar   $phar
 * @param string $sFile
 * @param null   $baseDir
 */
function addFile($phar, $sFile, $baseDir = null)
{
    if (null !== $baseDir) {
        $phar->addFromString(substr($sFile, strlen($baseDir) + 1), php_strip_whitespace($sFile));
    } else {
        $phar->addFromString($sFile, php_strip_whitespace($sFile));
    }
}
開發者ID:pgiacometto,項目名稱:zf2rapid,代碼行數:15,代碼來源:zf2rapid-create-phar.php

示例4: addFile

 /**
  * @param \Phar $phar
  * @param SplFileInfo $file
  */
 private function addFile(\Phar $phar, SplFileInfo $file)
 {
     $path = $file->getRelativePathname();
     $content = file_get_contents($file);
     $content = preg_replace('{^#!/usr/bin/env php\\s*}', '', $content);
     $phar->addFromString($path, $content);
 }
開發者ID:webcreate,項目名稱:conveyor,代碼行數:11,代碼來源:PharTask.php

示例5: 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);
 }
開發者ID:kawahara,項目名稱:symfony-bootstrapper,代碼行數:26,代碼來源:Compiler.php

示例6: run

 public function run()
 {
     $this->printTaskInfo('Creating {filename}', ['filename' => $this->filename]);
     $this->phar->setSignatureAlgorithm(\Phar::SHA1);
     $this->phar->startBuffering();
     $this->printTaskInfo('Packing {file-count} files into phar', ['file-count' => count($this->files)]);
     $this->startProgressIndicator();
     foreach ($this->files as $path => $content) {
         $this->phar->addFromString($path, $content);
         $this->advanceProgressIndicator();
     }
     $this->phar->stopBuffering();
     $this->advanceProgressIndicator();
     if ($this->compress and in_array('GZ', \Phar::getSupportedCompression())) {
         if (count($this->files) > 1000) {
             $this->printTaskInfo('Too many files. Compression DISABLED');
         } else {
             $this->printTaskInfo('{filename} compressed', ['filename' => $this->filename]);
             $this->phar = $this->phar->compressFiles(\Phar::GZ);
         }
     }
     $this->advanceProgressIndicator();
     $this->stopProgressIndicator();
     $this->printTaskSuccess('{filename} produced', ['filename' => $this->filename]);
     return Result::success($this, '', ['time' => $this->getExecutionTime()]);
 }
開發者ID:greg-1-anderson,項目名稱:Robo,代碼行數:26,代碼來源:PackPhar.php

示例7: run

 public function run()
 {
     $this->printTaskInfo("Creating <info>{$this->filename}</info>");
     $this->phar->setSignatureAlgorithm(\Phar::SHA1);
     $this->phar->startBuffering();
     $this->printTaskInfo('Packing ' . count($this->files) . ' files into phar');
     $progress = new ProgressBar($this->getOutput());
     $progress->start(count($this->files));
     $this->startTimer();
     foreach ($this->files as $path => $content) {
         $this->phar->addFromString($path, $content);
         $progress->advance();
     }
     $this->phar->stopBuffering();
     $progress->finish();
     $this->getOutput()->writeln('');
     if ($this->compress and in_array('GZ', \Phar::getSupportedCompression())) {
         if (count($this->files) > 1000) {
             $this->printTaskInfo("Too many files. Compression DISABLED");
         } else {
             $this->printTaskInfo($this->filename . " compressed");
             $this->phar = $this->phar->compressFiles(\Phar::GZ);
         }
     }
     $this->stopTimer();
     $this->printTaskSuccess("<info>{$this->filename}</info> produced");
     return Result::success($this, '', ['time' => $this->getExecutionTime()]);
 }
開發者ID:roland-d,項目名稱:Robo,代碼行數:28,代碼來源:PackPhar.php

示例8: addFile

 private function addFile(\Phar $phar, \SplFileInfo $file)
 {
     $path = str_replace(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR, '', $file->getRealPath());
     $content = file_get_contents($file);
     $content = $this->stripWhitespace($content);
     $phar->addFromString($path, $content);
 }
開發者ID:bcncommerce,項目名稱:magebuild,代碼行數:7,代碼來源:Compiler.php

示例9: addFile

 protected function addFile(\Phar $phar, \splFileInfo $file, $strip = true)
 {
     $path = str_replace(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR, '', $file->getRealPath());
     $content = file_get_contents($file);
     if ($strip) {
         $content = self::stripWhitespace($content);
     }
     $phar->addFromString($path, $content);
 }
開發者ID:rtoshiro,項目名稱:json-poxo,代碼行數:9,代碼來源:Compiler.php

示例10: addFile

 /**
  * Add a file into the Phar binary
  * @param \SplFileInfo $file The file to be added
  * @since 1.0.0
  */
 protected function addFile(\SplFileInfo $file)
 {
     $path = str_replace($this->root, '', $file->getRealPath());
     $content = file_get_contents($file);
     $content = preg_replace('{^#!/usr/bin/env php\\s*}', '', $content);
     if ($this->processor instanceof ProcessorInterface) {
         $content = $this->processor->process($content);
     }
     $this->phar->addFromString($path, $content);
 }
開發者ID:mauris,項目名稱:concrete,代碼行數:15,代碼來源:Compiler.php

示例11: addFile

 protected function addFile(\Phar $phar, \SplFileInfo $file, $strip = true)
 {
     $path = str_replace(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR, '', $file->getRealPath());
     $content = file_get_contents($file);
     if ($strip) {
         $content = self::stripWhitespace($content);
     }
     $content = preg_replace("/const VERSION = '.*?';/", "const VERSION = '" . $this->version . "';", $content);
     $phar->addFromString($path, $content);
 }
開發者ID:shomimn,項目名稱:builder,代碼行數:10,代碼來源:Compiler.php

示例12: addFile

 protected function addFile(File $file, $path, $stripBin = false)
 {
     $this->output->writeln(' <info>*</info> Add php file ' . $path);
     $content = $file->getContents();
     if ($stripBin) {
         $content = preg_replace('~^#!/usr/bin/env php\\s*~', '', $content);
         $content = str_replace('BundlerPackCommand', 'UpdateCommand', $content);
     }
     $this->phar->addFromString($path, $content);
 }
開發者ID:bit3,項目名稱:contao-management-console,代碼行數:10,代碼來源:BundlerPackCommand.php

示例13: addFile

 /**
  * Add a file to the psysh Phar.
  *
  * @param Phar $phar
  * @param SplFileInfo $file
  * @param bool $strip (default: true)
  */
 private function addFile($phar, $file, $strip = true)
 {
     $path = str_replace(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR, '', $file->getRealPath());
     $content = file_get_contents($file);
     if ($strip) {
         $content = $this->stripWhitespace($content);
     } elseif ('LICENSE' === basename($file)) {
         $content = "\n" . $content . "\n";
     }
     $phar->addFromString($path, $content);
 }
開發者ID:JesseDarellMoore,項目名稱:CS499,代碼行數:18,代碼來源:Compiler.php

示例14: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Building Phar archive');
     $file = 'build/zip.phar.php';
     if (file_exists($file)) {
         $output->writeln('Removing previous phar archive');
         unlink($file);
     }
     $output->writeln('Buffering contents ...');
     $phar = new \Phar($file, 0, 'zip.phar');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     $finder = new Finder();
     $finder->in(array('app', 'src', 'vendor'))->files(array('*.php', '*.js'));
     $count = $finder->count();
     $output->writeln(sprintf('Found %d entries', $count));
     $step = $count / 100;
     $index = 0;
     $indexStep = 0;
     /** @var ProgressHelper $progress */
     $progress = $this->getHelperSet()->get('progress');
     $progress->setFormat(' [%bar%] %percent%%');
     $progress->start($output, 100);
     /** @var SplFileInfo $file */
     $basePath = realpath(__DIR__ . '/../../../../../');
     foreach ($finder as $file) {
         $path = str_replace($basePath, '', $file->getRealPath());
         $path = ltrim($path, DIRECTORY_SEPARATOR);
         $path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
         $phar->addFromString($path, $file->getContents());
         if ($index++ % $step == 0 && $indexStep < 100) {
             $progress->advance();
             $indexStep++;
         }
     }
     $phar->addFromString('index.php', file_get_contents($basePath . DIRECTORY_SEPARATOR . 'index.php'));
     $phar->setStub('<?php Phar::mapPhar("zip.phar"); define("PHAR_RUNNING", true); /*Phar::interceptFileFuncs();*/ require "phar://zip.phar/index.php"; __HALT_COMPILER();');
     $phar->stopBuffering();
     $progress->finish();
     $output->writeln('Build complete. Phar archive has been deployed to build/zip.phar.php');
 }
開發者ID:kzykhys,項目名稱:portable-zipcode-api,代碼行數:44,代碼來源:PharCommand.php

示例15: build

    public function build()
    {
        $file = getTmpFile("phar");
        $phar = new \Phar($file);
        $phar->setStub("<?php __HALT_COMPILER(); ?>");
        $phar->setSignatureAlgorithm(\Phar::SHA1);
        $phar->startBuffering();
        $namespace = "_{$this->name}" . randomClass(8, "\\_");
        $class = randomClass(8);
        $main = "{$namespace}\\{$class}";
        $manifest = ["name" => $this->name, "version" => $this->version, "authors" => $this->authors, "api" => "1.9.0", "main" => $main, "commands" => []];
        foreach ($this->cmds as $cmd) {
            $manifest["commands"][$cmd->name] = ["description" => $cmd->desc, "usage" => $cmd->usage];
        }
        $phar->addFromString("plugin.yml", yaml_emit($manifest));
        $mainClass = <<<EOS
<?php
namespace {$namespace};
use pocketmine\\command as cmd;
use pocketmine\\event as evt;
class {$class} extends \\pocketmine\\plugin\\PluginBase implements evt\\Listener{
public function onCommand(cmd\\CommandSender \$sender, cmd\\Command\\ \$cmd, \$lbl, array \$args){
switch(\$cmd->getName()){
EOS;
        foreach ($this->cmds as $cmd) {
            $mainClass .= "case " . var_export($cmd->name, true) . ":" . PHP_EOL;
            $mainClass .= "return \$this->onCommand_{$cmd->name}(\$args, \$sender);" . PHP_EOL;
        }
        $mainClass .= "}" . PHP_EOL . "return false;" . PHP_EOL . "}" . PHP_EOL;
        foreach ($this->cmds as $cmd) {
            $mainClass .= $cmd->executor->toPhp();
        }
        $mainClass .= "}";
        $phar->addFromString("src/" . str_replace("\\", "/", $main) . ".php", $mainClass);
        //		$phar->compressFiles(\Phar::GZ);
        $phar->stopBuffering();
        $path = $phar->getPath();
        header("Content-Type: application/octet-stream");
        echo file_get_contents($path);
        //		unlink($path);
    }
開發者ID:GoneTone,項目名稱:web-server-source,代碼行數:41,代碼來源:Plugin.php


注:本文中的Phar::addFromString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。