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


PHP Phar::createDefaultStub方法代码示例

本文整理汇总了PHP中Phar::createDefaultStub方法的典型用法代码示例。如果您正苦于以下问题:PHP Phar::createDefaultStub方法的具体用法?PHP Phar::createDefaultStub怎么用?PHP Phar::createDefaultStub使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phar的用法示例。


在下文中一共展示了Phar::createDefaultStub方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

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

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

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

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

示例6: createPharFile

function createPharFile($pharFilePath, $originalFile)
{
    $originalFile = realpath($originalFile);
    try {
        $phar = new Phar($pharFilePath);
        $phar->addFile($originalFile);
        $phar->compressFiles(Phar::GZ);
        $phar->stopBuffering();
        $phar->setStub($phar->createDefaultStub($pharFilePath));
        $phar->setStub("<?php Phar::mapPhar();\ninclude 'phar://{$pharFilePath}/{$originalFile}'; __HALT_COMPILER(); ?>");
    } catch (Exception $e) {
        var_dump($e->getMessage());
    }
}
开发者ID:poyu007,项目名称:heisoo_env,代码行数:14,代码来源:toPhar.php

示例7: build

 /**
  * @param string $cli
  * @param string $web
  * @param array  $ignored
  * @param bool   $ignoreScm
  *
  * @return $this
  */
 public function build($cli = null, $web = null, array $ignored = null, $ignoreScm = true)
 {
     // debug
     $this->debug("Creating phar-file ...");
     // create phar
     $pharAlias = basename($this->filename);
     $this->phar = new \Phar($this->targetName, 0, $pharAlias);
     $this->phar->setSignatureAlgorithm(\Phar::SHA1);
     // start buffering
     $this->phar->startBuffering();
     // normalize ignored-array if present
     if (null !== $ignored) {
         foreach ($ignored as &$path) {
             $path = \str_replace($this->sourceDir, '', $path);
             if (\DIRECTORY_SEPARATOR !== \substr($path, 0, 1)) {
                 $path = \DIRECTORY_SEPARATOR . $path;
             }
         }
     }
     // indexing source
     $this->indexSourceDir($this->sourceDir, $ignored, $ignoreScm);
     // debug
     $this->debug(\str_repeat('-', 76));
     $this->debug("--> Indexing done.");
     // normalize entry files
     if ($cli) {
         $cli = \str_replace($this->sourceDir, '', $cli);
         $this->debug(\sprintf("--> Setting entry-point for CLI-execution to '%s'", $cli));
     }
     if ($web) {
         $web = \str_replace($this->sourceDir, '', $web);
         $this->debug(\sprintf("--> Setting entry-point for WEB-execution to '%s'", $web));
     }
     // set entry-point
     $this->phar->setStub($this->phar->createDefaultStub($cli, $web));
     // stop the buffering
     $this->phar->stopBuffering();
     // return fluid interface
     return $this;
 }
开发者ID:sweikenb,项目名称:php-library,代码行数:48,代码来源:PharBuilder.php

示例8: Phar

$binaryFilename = "bin/{$binary}";
if (file_exists($pharFilename)) {
    Phar::unlinkArchive($pharFilename);
}
if (file_exists($binaryFilename)) {
    Phar::unlinkArchive($binaryFilename);
}
$phar = new Phar($pharFilename, FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO, $binary);
$phar->startBuffering();
$directories = array('src', 'vendor', 'scripts');
foreach ($directories as $dirname) {
    $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirname));
    while ($iterator->valid()) {
        if ($iterator->isFile()) {
            $path = $iterator->getPathName();
            if ('php' == strtolower($iterator->getExtension())) {
                $contents = php_strip_whitespace($path);
                $phar->addFromString($path, $contents);
            } else {
                $phar->addFile($path);
            }
        }
        $iterator->next();
    }
}
$stub = "#!/usr/bin/env php\n" . $phar->createDefaultStub($scriptFilename);
$phar->setStub($stub);
$phar->compressFiles(Phar::GZ);
$phar->stopBuffering();
rename($pharFilename, $binaryFilename);
chmod($binaryFilename, 0775);
开发者ID:gamegos,项目名称:php-code-sniffer,代码行数:31,代码来源:create-phar.php

示例9: get

    $dir = $dirName . "\\" . $src;
    $rp = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
    foreach ($rp as $file) {
        if ($file->isFile() && $file->getFilename() != ".." && $file->getFilename() != ".") {
            $pathBefore = substr($file->getPath(), 0, strlen($dir));
            $pathAfter = substr($file->getPath(), strlen($dir) + 1);
            $pathTo = "\\" . $suffix . ($pathAfter !== false ? $pathAfter . "\\" : "") . $file->getFilename();
            $phar->addFromString($pathTo, file_get_contents($file->getPath() . "/" . $file->getFilename()));
        }
    }
}
if (isset($composer["require"])) {
    while (list($library, $ver) = each($composer["require"])) {
        if (file_exists($dirName . "\\vendor\\" . $library)) {
            $dir = $dirName . "\\vendor\\" . $library . "\\src";
            $rp = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
        }
        foreach ($rp as $file) {
            if ($file->isFile() && $file->getFilename() != ".." && $file->getFilename() != ".") {
                $pathBefore = substr($file->getPath(), 0, strlen($dir));
                $pathAfter = substr($file->getPath(), strlen($dir) + 1);
                $pathTo = "\\" . $suffix . ($pathAfter !== false ? $pathAfter . "\\" : "") . $file->getFilename();
                $phar->addFromString($pathTo, file_get_contents($file->getPath() . "/" . $file->getFilename()));
            }
        }
    }
}
$stubSource = "<?php\r\n" . "class TMLoader {\r\n" . "    public static function get() {\r\n" . "        spl_autoload_register(function (\$class) {\r\n" . "            \$fileName = \"phar://{$pharName}/\" . \$class . \".php\";\r\n" . "            if (file_exists(\$fileName)) {\r\n" . "                include_once (\$fileName);\r\n" . "            }\r\n" . "        })\r\n;" . "    }\r\n" . "}";
$phar->addFromString("TMLoader.php", $stubSource);
$phar->setStub($phar->createDefaultStub('TMLoader.php'));
开发者ID:grinfeld,项目名称:phpjsonable,代码行数:30,代码来源:createphar.php

示例10: exportPHAR

 /**
  * Exports a PHAR file for the entire extension
  *
  * @param string $phar_name
  * @param string $output_dir
  * @param bool   $create_sub_directories
  *
  * @throws \Exception
  */
 public function exportPHAR($phar_name, $output_dir = '.', $create_sub_directories = true)
 {
     ini_set('phar.readonly', 0);
     $temp_dir = '/tmp' . DIRECTORY_SEPARATOR . 'PHPExport_' . rand(1, 9999);
     if (!file_exists($temp_dir) && !@mkdir($temp_dir)) {
         throw new \Exception("Could not create temp directory: {$temp_dir}");
     }
     $this->exportFiles($temp_dir, $create_sub_directories);
     $phar = new \Phar($output_dir . DIRECTORY_SEPARATOR . $phar_name, 0, $phar_name);
     $phar->buildFromDirectory($temp_dir, '#\\.php$#');
     $result = $phar->setStub($phar->createDefaultStub('cli/index.php', 'www/index.php'));
     if (!$result) {
         throw new \Exception('Could not set stub for phar: ' . $phar_name);
     }
 }
开发者ID:michalkoslab,项目名称:Helpers,代码行数:24,代码来源:ReflectionExtension.php

示例11: Phar

<?php

$phar = new Phar('jellytest.phar');
//指定压缩包的名称
$phar->startBuffering();
$phar->buildFromDirectory(__DIR__, '$(src|vendor)/.*\\.php$');
//第1个参数 指定压缩的目录, 第2个参数 通过正则来制定压缩文件的扩展名
//$phar->compressFiles(Phar::GZ); 指定压缩格式,Phar::GZ表示使用gzip来压缩此文件。也支持bz2压缩。参数修改为 PHAR::BZ2即可
$phar->setStub($phar->createDefaultStub('./vendor/autoload.php'));
#设置启动加载的文件。默认会自动加载并执行./vendor/autoload.php
$phar->stopBuffering();
/**
使用phar压缩包
include 'jellytest.phar';
include 'jellytest.phar/code/page.php';
*/
开发者ID:jellycheng,项目名称:learnlaravel,代码行数:16,代码来源:build.php

示例12: dirname

<?php

$dir = dirname(__FILE__) . '/broken.dirname';
mkdir($dir, 0777);
$fname = $dir . '/dotted_path.phar';
$stub = Phar::createDefaultStub();
$file = $stub;
$files = array();
$files['a'] = 'this is a';
$files['b'] = 'this is b';
include 'files/phar_test.inc';
$phar = new Phar($fname);
foreach ($phar as $entry) {
    echo file_get_contents($entry) . "\n";
}
?>
===DONE===
开发者ID:zaky-92,项目名称:php-1,代码行数:17,代码来源:ext_phar_tests_phar_dotted_path.php

示例13: unlink

<?php

$destFile = __DIR__ . '/bin/mtags.phar';
if (file_exists($destFile)) {
    unlink($destFile);
}
$phar = new Phar($destFile);
$phar->addFile(__DIR__ . '/mtags.php', 'mtags.php');
$phar->setStub($phar->createDefaultStub('mtags.php'));
// for completeness
$phar->addFile(__FILE__, basename(__FILE__));
$phar->addFile(__DIR__ . '/composer.json', 'composer.json');
foreach (glob(__DIR__ . '/src/*.php') as $file) {
    $phar->addFile($file, 'src/' . basename($file));
}
$phar->addFile(__DIR__ . '/vendor/autoload.php', 'vendor/autoload.php');
foreach (glob(__DIR__ . '/vendor/composer/*.php') as $file) {
    $phar->addFile($file, 'vendor/composer/' . basename($file));
}
$phar->addFile(__DIR__ . '/vendor/pwfisher/command-line-php/CommandLine.php', 'vendor/pwfisher/command-line-php/CommandLine.php');
$getid3dir = 'vendor/james-heinrich/getid3/getid3';
$getid3modules = ['getid3', 'module.audio.', 'module.misc.iso', 'module.misc.cue', 'module.tag.', 'module.audio-video.riff', 'module.audio-video.quicktime'];
foreach (glob(__DIR__ . '/' . $getid3dir . '/*.php') as $file) {
    $basename = basename($file);
    foreach ($getid3modules as $module) {
        if (strpos($basename, $module) === 0) {
            $phar->addFile($file, $getid3dir . '/' . $basename);
            break;
        }
    }
}
开发者ID:vensko,项目名称:mtags-sync,代码行数:31,代码来源:build.php

示例14: dirname

<?php

define('SRC_ROOT', dirname(__FILE__) . '/src');
define('BUILD_ROOT', dirname(__FILE__) . '/build');
try {
    $phar = new Phar(BUILD_ROOT . '/PeriscopeDownloader.phar', FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, 'PeriscopeDownloader.phar');
    $phar->buildFromDirectory(SRC_ROOT, '/.php$/');
    $phar->setMetadata(array('version' => '1.0', 'author' => 'jColfej', 'description' => 'Easy download periscope replay !'));
    $phar->setStub('#!/usr/bin/env php' . PHP_EOL . $phar->createDefaultStub('index.php'));
    echo 'File created : build/PeriscopeDownloader.phar' . PHP_EOL;
} catch (Exception $e) {
    echo '/!\\ Erreur on PHAR creation ...' . PHP_EOL;
    echo PHP_EOL;
    echo 'Error : ' . $e->getMessage() . PHP_EOL;
    echo 'File : ' . $e->getFile() . PHP_EOL;
    echo PHP_EOL;
    echo $e->getTraceAsString() . PHP_EOL;
}
开发者ID:jcolfej,项目名称:PeriscopeDownloader,代码行数:18,代码来源:build.php

示例15: Phar

ini_set("display_errors", "on");
require_once "../src/configuration/config.php";
$EOL_PRINT = "<br/>\n";
echo "***********************************" . $EOL_PRINT;
echo "* <strong>Creating a phar file</strong>" . $EOL_PRINT;
echo "*                                  " . $EOL_PRINT;
echo "* This script builds the .phar file" . $EOL_PRINT;
echo "* for using the framework in a     " . $EOL_PRINT;
echo "* archive.                         " . $EOL_PRINT;
echo "***********************************" . $EOL_PRINT;
echo "* <strong>BUILD_SCRIPT_VERSION</strong> " . $BUILD_SCRIPT_VERSION . $EOL_PRINT;
echo "* <strong>FRAMEWORK_VERSION</strong> " . $FRAMEWORK_VERSION . $EOL_PRINT;
echo "***********************************" . $EOL_PRINT . $EOL_PRINT;
$filename = "epages-rest-php-" . $FRAMEWORK_VERSION . ".phar";
$latestFilename = "epages-rest-php.phar";
if (file_exists($filename)) {
    echo "<strong>Version already exists. Delete this version of increase the version.</strong>";
} else {
    echo "<ul>";
    echo "<li><strong>Creating the .phar</strong></li>";
    $phar = new Phar($filename);
    echo "<li><strong>Adding all files</strong></li>";
    $phar->buildFromDirectory('../src');
    echo "<li><strong>Create and set default stub</strong></li>";
    $phar->setStub($phar->createDefaultStub('Shop.class.php'));
    echo "<li><strong>Delete the latest file</strong></li>";
    unlink($latestFilename);
    echo "<li><strong>Copy to latest</strong></li>";
    copy($filename, $latestFilename);
    echo "</ul>";
}
开发者ID:Quaese,项目名称:ep6client-php,代码行数:31,代码来源:make.php


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