本文整理汇总了PHP中Phar::setStub方法的典型用法代码示例。如果您正苦于以下问题:PHP Phar::setStub方法的具体用法?PHP Phar::setStub怎么用?PHP Phar::setStub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phar
的用法示例。
在下文中一共展示了Phar::setStub方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute(CommandSender $sender, $commandLabel, array $args)
{
if (!$this->testPermission($sender)) {
return false;
}
if (count($args) === 0) {
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
return true;
}
$pluginName = trim(implode(" ", $args));
if ($pluginName === "" or !($plugin = Server::getInstance()->getPluginManager()->getPlugin($pluginName)) instanceof Plugin) {
$sender->sendMessage(TextFormat::RED . "プラグインが存在しません");
return true;
}
$description = $plugin->getDescription();
if (!$plugin->getPluginLoader() instanceof FolderPluginLoader) {
$sender->sendMessage(TextFormat::RED . "プラグイン " . $description->getName() . "はフォルダではありません");
return true;
}
$pharPath = Server::getInstance()->getPluginPath() . DIRECTORY_SEPARATOR . "PocketMine-MO" . DIRECTORY_SEPARATOR . $description->getName() . "_v" . $description->getVersion() . ".phar";
if (file_exists($pharPath)) {
$sender->sendMessage("pharファイルが既に存在しているため、上書きします");
@unlink($pharPath);
}
$phar = new \Phar($pharPath);
$phar->setMetadata(["name" => $description->getName(), "version" => $description->getVersion(), "main" => $description->getMain(), "api" => $description->getCompatibleApis(), "geniapi" => $description->getCompatibleGeniApis(), "depend" => $description->getDepend(), "description" => $description->getDescription(), "authors" => $description->getAuthors(), "website" => $description->getWebsite(), "creator" => "PocketMine-MO MakePluginCommand", "creationDate" => time()]);
if ($description->getName() === "DevTools") {
$phar->setStub('<?php require("phar://". __FILE__ ."/src/DevTools/ConsoleScript.php"); __HALT_COMPILER();');
} else {
$phar->setStub('<?php echo "PocketMine-MP/ plugin ' . $description->getName() . ' v' . $description->getVersion() . '\\nThis file has been generated using PocketMine-MO by Meshida at ' . date("r") . '\\n----------------\\n";if(extension_loaded("phar")){$phar = new \\Phar(__FILE__);foreach($phar->getMetadata() as $key => $value){echo ucfirst($key).": ".(is_array($value) ? implode(", ", $value):$value)."\\n";}} __HALT_COMPILER();');
}
$phar->setSignatureAlgorithm(\Phar::SHA1);
$reflection = new \ReflectionClass("pocketmine\\plugin\\PluginBase");
$file = $reflection->getProperty("file");
$file->setAccessible(true);
$filePath = rtrim(str_replace("\\", "/", $file->getValue($plugin)), "/") . "/";
$phar->startBuffering();
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($filePath)) as $file) {
$path = ltrim(str_replace(["\\", $filePath], ["/", ""], $file), "/");
if ($path[0] === "." or strpos($path, "/.") !== false) {
continue;
}
$phar->addFile($file, $path);
$sender->sendMessage($path . "を追加しています...");
}
foreach ($phar as $file => $finfo) {
/** @var \PharFileInfo $finfo */
if ($finfo->getSize() > 1024 * 512) {
$finfo->compress(\Phar::GZ);
}
}
if (!isset($args[1]) or isset($args[1]) and $args[1] != "nogz") {
$phar->compressFiles(\Phar::GZ);
}
$phar->stopBuffering();
$sender->sendMessage("pharプラグイン " . $description->getName() . " v" . $description->getVersion() . " は" . $pharPath . "上に生成されました");
return true;
}
示例2: run
/**
* @param bool $verbose
*/
function run($verbose = false)
{
if ($verbose) {
printf("Using stub '%s'...\n", basename($this->stub));
}
$stub = preg_replace_callback('/^#include <([^>]+)>/m', function ($includes) {
return file_get_contents($includes[1], true, null, 5);
}, file_get_contents($this->stub));
if ($this->phar->isCompressed() && substr($stub, 0, 2) === "#!") {
$stub = substr($stub, strpos($stub, "\n") + 1);
}
$this->phar->setStub($stub);
}
示例3: 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());
}
}
示例4: makePlugin
/**
* Makes a .phar packaged PocketMine plugin from a source directory.
*
* @param $sourcePath
* @param $pharOutputLocation
* @param $options
* @return bool
* @throws \Exception
*/
public static function makePlugin($sourcePath, $pharOutputLocation, $options)
{
/* Removes Leading '/' */
$sourcePath = rtrim(str_replace("\\", "/", realpath($sourcePath)), "/") . "/";
$description = self::getPluginDescription($sourcePath . "/plugin.yml");
if ($options & self::MAKEPLUGIN_REAL_OUTPUT_PATH) {
$pharPath = $pharOutputLocation;
} else {
$pharPath = $pharOutputLocation . DIRECTORY_SEPARATOR . $description->getName() . "_v" . $description->getVersion() . ".phar";
}
if (file_exists($pharPath)) {
throw new \Exception("Phar path already exists");
}
$phar = new \Phar($pharPath);
$phar->setMetadata(["name" => $description->getName(), "version" => $description->getVersion(), "main" => $description->getMain(), "api" => $description->getCompatibleApis(), "depend" => $description->getDepend(), "description" => $description->getDescription(), "authors" => $description->getAuthors(), "website" => $description->getWebsite(), "creationDate" => time()]);
$phar->setStub('<?php echo "PocketMine-MP plugin ' . $description->getName() . ' v' . $description->getVersion() . '\\nThis file has been generated using DevTools v' . self::getVersion() . ' at ' . date("r") . '\\n----------------\\n";if(extension_loaded("phar")){$phar = new \\Phar(__FILE__);foreach($phar->getMetadata() as $key => $value){echo ucfirst($key).": ".(is_array($value) ? implode(", ", $value):$value)."\\n";}} __HALT_COMPILER();');
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($sourcePath)) as $file) {
$path = ltrim(str_replace(["\\", $sourcePath], ["/", ""], $file), "/");
if ($path[0] === "." or strpos($path, "/.") !== false) {
continue;
}
$phar->addFile($file, $path);
}
if ($options * self::MAKEPLUGIN_COMPRESS) {
$phar->compressFiles(\Phar::GZ);
}
$phar->stopBuffering();
return true;
}
示例5: 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)');
}
}
示例6: init
/**
* Initialize the package creator
*/
function init()
{
try {
if (file_exists($this->path)) {
@unlink($this->path);
}
$ext = strstr(strrchr($this->path, '-'), '.');
if (!$ext) {
$ext = strstr(strrchr($this->path, '/'), '.');
if (!$ext) {
$ext = strstr(strrchr($this->path, '\\'), '.');
}
}
if (!$ext) {
$ext = strstr($this->path, '.');
}
$a = $this->_classname;
$this->phar = new $a($this->path);
if ($this->phar instanceof Phar) {
$this->phar = $this->phar->convertToExecutable($this->format, $this->compression, $ext);
} else {
$this->phar = $this->phar->convertToData($this->format, $this->compression, $ext);
}
$this->phar->startBuffering();
if ($this->phar instanceof Phar) {
$this->phar->setStub($this->stub);
}
if ($this->format == Phar::ZIP) {
$this->compression = $comp;
}
} catch (Exception $e) {
throw new \Pyrus\Developer\Creator\Exception('Cannot open Phar archive ' . $this->path, $e);
}
$this->_started = false;
}
示例7: 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();
}
示例8: 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"));
}
示例9: _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();
}
示例10: 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));
}
示例11: build
public function build($filename, $stub)
{
if (file_exists($filename)) {
unlink($filename);
}
$phar = new \Phar($filename, 0, $this->aliasName != '' ? $this->aliasName : basename($filename));
$phar->startBuffering();
$phar->setStub($stub);
if ($this->key !== NULL) {
$privateKey = '';
openssl_pkey_export($this->key, $privateKey);
$phar->setSignatureAlgorithm(\Phar::OPENSSL, $privateKey);
$keyDetails = openssl_pkey_get_details($this->key);
file_put_contents($filename . '.pubkey', $keyDetails['key']);
} else {
$phar->setSignatureAlgorithm($this->selectSignatureType($phar));
}
$basedir = $this->basedir ? $this->basedir : $this->directories[0];
foreach ($this->directories as $directory) {
$phar->buildFromIterator($this->scanner->__invoke($directory), $basedir);
}
if ($this->compression !== \Phar::NONE) {
$phar->compressFiles($this->compression);
}
$phar->stopBuffering();
}
示例12: 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);
}
示例13: 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());
}
示例14: 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'));
}
示例15: 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));
}