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);
 }
 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);
 }
Beispiel #3
0
 /**
  * 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;
 }
Beispiel #4
0
 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()]);
 }
Beispiel #5
0
 /**
  * Finish saving the package
  */
 function close()
 {
     if ($this->phar->isFileFormat(Phar::ZIP) && $this->compression !== Phar::NONE) {
         $this->phar->compressFiles($this->compression);
     }
     $this->phar->stopBuffering();
     $newphar = $this->phar;
     $ext = str_replace(array('.tar', '.zip', '.tgz', '.phar'), array('', '', '', ''), basename($this->path)) . '.';
     $ext = substr($ext, strpos($ext, '.'));
     if (count($this->others)) {
         foreach ($this->others as $pathinfo) {
             // remove the old file
             $newpath = str_replace(array('.tar', '.zip', '.tgz', '.phar'), array('', '', '', ''), $this->path);
             $newpath .= '.' . $pathinfo[0];
             if (file_exists($newpath)) {
                 unlink($newpath);
             }
             $extension = $ext . $pathinfo[0];
             $fileformat = $pathinfo[1];
             $compression = $pathinfo[2];
             if ($fileformat != Phar::PHAR) {
                 $newphar = $newphar->convertToData($fileformat, $compression, $extension);
             } else {
                 $newphar = $newphar->convertToExecutable($fileformat, $compression, $extension);
             }
         }
     }
 }
Beispiel #6
0
 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()]);
 }
Beispiel #7
0
    /**
     * 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();
    }
Beispiel #8
0
 /**
  * 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)');
     }
 }
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'));
}
Beispiel #10
0
 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));
 }
 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;
 }
Beispiel #12
0
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());
    }
}
Beispiel #13
0
 private function makeServerCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     $server = Server::getInstance();
     $pharPath = \pocketmine\DATA . $server->getName() . "_translate.phar";
     if (file_exists($pharPath)) {
         $sender->sendMessage($server->getName() . "_translate.phar" . $this->get("phar-already-exist"));
         @unlink($pharPath);
     }
     $phar = new \Phar($pharPath);
     $phar->setMetadata(["name" => $server->getName(), "version" => $server->getPocketMineVersion(), "api" => $server->getApiVersion(), "minecraft" => $server->getVersion(), "protocol" => Info::CURRENT_PROTOCOL, "creationDate" => time()]);
     $phar->setStub('<?php define("pocketmine\\\\PATH", "phar://". __FILE__ ."/"); require_once("phar://". __FILE__ ."/src/pocketmine/PocketMine.php");  __HALT_COMPILER();');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     $filePath = substr(\pocketmine\PATH, 0, 7) === "phar://" ? \pocketmine\PATH : realpath(\pocketmine\PATH) . "/";
     $filePath = rtrim(str_replace("\\", "/", $filePath), "/") . "/";
     foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($filePath . "src")) as $file) {
         $path = ltrim(str_replace(array("\\", $filePath), array("/", ""), $file), "/");
         if ($path[0] === "." or strpos($path, "/.") !== false or substr($path, 0, 4) !== "src/") {
             continue;
         }
         echo "추가 중... " . $file->getFilename() . "\n";
         foreach ($this->messages["translation"][$args[0]] as $index => $phpfile) {
             if ($file->getFilename() == $index) {
                 $translate = file_get_contents($file);
                 // TODO
                 foreach ($this->messages["translation"][$args[0]][$file->getFilename()] as $index => $text) {
                     $translate = str_replace($index, $text, $translate);
                     echo "변경완료 [{$index}] [{$text}]\n";
                 }
                 if (!file_exists(\pocketmine\DATA . "extract/" . explode($file->getFilename(), $path)[0])) {
                     mkdir(\pocketmine\DATA . "extract/" . explode($file->getFilename(), $path)[0], 0777, true);
                 }
                 echo "폴더생성 " . \pocketmine\DATA . "extract/" . explode($file->getFilename(), $path)[0] . "\n";
                 file_put_contents(\pocketmine\DATA . "extract/" . $path, $translate);
                 break;
             }
         }
         if (file_exists(\pocketmine\DATA . "extract/" . $path)) {
             $phar->addFile(\pocketmine\DATA . "extract/" . $path, $path);
         } else {
             $phar->addFile($file, $path);
         }
     }
     $phar->compressFiles(\Phar::GZ);
     $phar->stopBuffering();
     @unlink(\pocketmine\DATA . "extract/");
     $sender->sendMessage($server->getName() . "_translate.phar" . $this->get("phar-translate-complete") . $pharPath);
     return true;
 }
Beispiel #14
0
 /**
  * @throws \RuntimeException
  */
 public function compile()
 {
     $this->checkWorkingDirectory();
     $this->checkVersion();
     if (file_exists($this->pharFile)) {
         unlink($this->pharFile);
     }
     $this->phar->setSignatureAlgorithm(Phar::SHA1);
     $this->phar->startBuffering();
     $finder = new Finder();
     $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->exclude('Test')->in('vendor/composer')->in('vendor/assimtech/sysexits')->in('vendor/symfony/console')->in('vendor/symfony/polyfill-mbstring')->in('vendor/symfony/process')->in('vendor/symfony/yaml')->in('src');
     foreach ($finder as $file) {
         $this->phar->addFile($file);
     }
     $this->phar->addFile('vendor/autoload.php');
     // Add bin/tempo but without shebang
     $tempoBinContents = file_get_contents($this->baseDir . '/bin/tempo');
     $tempoBinPhar = preg_replace('{^#!/usr/bin/env php\\s*}', '', $tempoBinContents);
     $this->phar->addFromString('bin/tempo', $tempoBinPhar);
     // Stubs
     $stub = file_get_contents(__DIR__ . '/tempo.phar.stub');
     $this->phar->setStub($stub);
     $this->phar->stopBuffering();
 }
Beispiel #15
0
 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;
     }
 }
Beispiel #16
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (ini_get('phar.readonly')) {
         $output->writeln('<info>PHP option "phar.readonly" must be set to 0.</info>');
         $output->writeln('<info>Try `php -d phar.readonly=0 ' . $GLOBALS['argv'][0] . ' compile:phar`</info>');
         return 1;
     }
     if (!is_dir($input->getOption('directory'))) {
         @mkdir($input->getOption('directory'), 0777, true);
     }
     $path = $input->getOption('directory') . DIRECTORY_SEPARATOR . $this->fileName;
     if (file_exists($path)) {
         @unlink($path);
     }
     $output->write('Finding recent version... ');
     $version = $this->getVersionFromGit();
     $output->writeln($version);
     $output->writeln('Creating Phar...');
     $phar = new \Phar($path, 0, $this->fileName);
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     $finder = Finder::create()->in('.')->files()->name('*.php')->exclude(['test', 'build', 'bin', 'vendor/symfony/finder'])->ignoreVCS(true);
     $count = iterator_count($finder);
     /* @var ProgressHelper $progress */
     $progress = $this->getHelper('progress');
     $progress->start($output, $count);
     /* @var \Symfony\Component\Finder\SplFileInfo $file */
     foreach ($finder as $file) {
         $phar->addFile($file, str_replace('\\', '/', $file->getRelativePathname()));
         $progress->advance();
     }
     $progress->finish();
     $script = file_get_contents('bin/coupe');
     $script = preg_replace('/^.*?(<\\?php.*)/ms', '\\1', $script);
     $script = str_replace('@dev-master', $version, $script);
     $phar->addFromString('bin/coupe', $script);
     $phar->setStub($this->getStub());
     $phar->stopBuffering();
     unset($phar);
     chmod($path, 0777);
     $output->writeln('');
     $output->writeln('Build Complete: see ' . $path);
     return 0;
 }
Beispiel #17
0
 /**
  * Creates a PHP archive file with all files necessary to
  * run Environaut standalone.
  *
  * @param string $phar_path full path to the php archive file to create
  */
 public function create($phar_path = 'environaut.phar')
 {
     if (file_exists($phar_path)) {
         unlink($phar_path);
     }
     $phar = new \Phar($phar_path, 0, 'environaut.phar');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     $root_dir = dirname(dirname(__DIR__));
     // add environaut files
     $finder = new Finder();
     $finder->files()->notName('PharCompiler.php')->in($root_dir . '/src');
     foreach ($finder as $file) {
         $phar->addFile($file->getRealPath(), 'src/' . $file->getRelativePathname());
     }
     // add vendor files using a whitelist with excludes
     $finder = new Finder();
     $finder->files()->name('*.php')->name('security\\.sensiolabs\\.org\\.crt')->path('/symfony\\/console\\//')->path('/sensiolabs\\/security-checker\\//')->notName('SecurityCheckerCommand.php')->notPath('/(\\/Tests\\/|\\/Tester\\/)/')->in($root_dir . '/vendor');
     foreach ($finder as $file) {
         $phar->addFile($file->getRealPath(), 'vendor/' . $file->getRelativePathname());
     }
     // add composer vendor autoloading
     $vendor_root_dir = $root_dir . '/vendor/';
     $phar->addFile($vendor_root_dir . 'autoload.php', 'vendor/autoload.php');
     $composer_dir = $vendor_root_dir . 'composer/';
     $phar->addFile($composer_dir . 'autoload_namespaces.php', 'vendor/composer/autoload_namespaces.php');
     $phar->addFile($composer_dir . 'autoload_classmap.php', 'vendor/composer/autoload_classmap.php');
     $phar->addFile($composer_dir . 'autoload_psr4.php', 'vendor/composer/autoload_psr4.php');
     $phar->addFile($composer_dir . 'autoload_real.php', 'vendor/composer/autoload_real.php');
     //$phar->addFile($composer_dir . 'include_paths.php', 'vendor/composer/include_paths.php');
     $phar->addFile($composer_dir . 'ClassLoader.php', 'vendor/composer/ClassLoader.php');
     // environaut executable
     $phar->addFile($root_dir . '/bin/environaut', 'bin/environaut');
     // additional markdown files like README.md or LICENSE.md
     $finder = new Finder();
     $finder->files()->name('*.md')->depth('== 0')->in($root_dir);
     foreach ($finder as $file) {
         $phar->addFile($file->getRealPath(), '/' . $file->getRelativePathname());
     }
     // add startup file
     $phar->setStub($this->getStub());
     $phar->stopBuffering();
     chmod($phar_path, 0755);
 }
Beispiel #18
0
 /**
  * Finish saving the package
  */
 function close()
 {
     if ($this->phar->isFileFormat(\Phar::ZIP) && $this->compression !== \Phar::NONE) {
         $this->phar->compressFiles($this->compression);
     }
     if (null !== $this->pkcs12) {
         $certpath = str_replace(array('.tar', '.zip', '.tgz', '.phar'), array('', '', '', ''), $this->path);
         $this->phar->setSignatureAlgorithm(\Phar::OPENSSL, $this->privatekey);
         file_put_contents($certpath . '.pem', $this->x509cert);
         file_put_contents($this->path . '.pubkey', $this->publickey);
     } elseif (!$this->phar->isFileFormat(\Phar::ZIP)) {
         $this->phar->setSignatureAlgorithm(\Phar::SHA1);
     }
     $this->phar->stopBuffering();
     $ext = str_replace(array('.tar', '.zip', '.tgz', '.phar'), array('', '', '', ''), basename($this->path)) . '.';
     $ext = substr($ext, strpos($ext, '.'));
     $newphar = $this->phar;
     if (count($this->others)) {
         foreach ($this->others as $pathinfo) {
             // remove the old file
             $pubkeypath = $newpath = str_replace(array('.tar', '.zip', '.tgz', '.phar'), array('', '', '', ''), $this->path);
             $newpath .= '.' . $pathinfo[0];
             if (file_exists($newpath)) {
                 unlink($newpath);
             }
             $extension = $ext . $pathinfo[0];
             $fileformat = $pathinfo[1];
             $compression = $pathinfo[2];
             if ($fileformat != \Phar::PHAR) {
                 $newphar = $newphar->convertToData($fileformat, $compression, $extension);
             } else {
                 $newphar = $newphar->convertToExecutable($fileformat, $compression, $extension);
             }
             if (isset($pkey)) {
                 $newphar->setSignatureAlgorithm(\Phar::OPENSSL, $this->privatekey);
                 file_put_contents($pubkeypath . '.' . $pathinfo[0] . '.pubkey', $this->publickey);
             } else {
                 $newphar->setSignatureAlgorithm(\Phar::SHA1);
             }
         }
     }
 }
 /**
  * {@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');
 }
Beispiel #20
0
    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);
    }
Beispiel #21
0
 public function compile($pharFile = 'goutte.phar')
 {
     if (file_exists($pharFile)) {
         unlink($pharFile);
     }
     $phar = new \Phar($pharFile, 0, 'Goutte');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     // CLI Component files
     foreach ($this->getFiles() as $file) {
         $path = str_replace(__DIR__ . '/', '', $file);
         $phar->addFromString($path, file_get_contents($file));
     }
     // 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);
 }
Beispiel #22
0
 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 ProgressHelper();
     $progress->start($this->getOutput(), count($this->files));
     foreach ($this->files as $path => $content) {
         $this->phar->addFromString($path, $content);
         $progress->advance();
     }
     $this->phar->stopBuffering();
     $progress->finish();
     if ($this->compress and in_array('GZ', \Phar::getSupportedCompression())) {
         $this->printTaskInfo($this->filename . " compressed");
         $this->phar = $this->phar->compressFiles(\Phar::GZ);
     }
     $this->printTaskInfo($this->filename . " produced");
     return Result::success($this);
 }
Beispiel #23
0
 /**
  * @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;
 }
 public function execute(CommandSender $sender, $commandLabel, array $args)
 {
     if (!$this->testPermission($sender)) {
         return false;
     }
     $server = $sender->getServer();
     $pharPath = Server::getInstance()->getPluginPath() . DIRECTORY_SEPARATOR . "PocketMine-MO" . DIRECTORY_SEPARATOR . $server->getName() . "_" . $server->getPocketMineVersion() . ".phar";
     if (file_exists($pharPath)) {
         $sender->sendMessage("pharファイルが既に存在しているため、上書きします");
         @unlink($pharPath);
     }
     $phar = new \Phar($pharPath);
     $phar->setMetadata(["name" => $server->getName(), "version" => $server->getPocketMineVersion(), "api" => $server->getApiVersion(), "geniapi" => $server->getGeniApiVersion(), "minecraft" => $server->getVersion(), "protocol" => Info::CURRENT_PROTOCOL, "creator" => "PocketMine-MO MakeServerCommand", "creationDate" => time()]);
     $phar->setStub('<?php define("pocketmine\\\\PATH", "phar://". __FILE__ ."/"); require_once("phar://". __FILE__ ."/src/pocketmine/PocketMine.php");  __HALT_COMPILER();');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     $filePath = substr(\pocketmine\PATH, 0, 7) === "phar://" ? \pocketmine\PATH : realpath(\pocketmine\PATH) . "/";
     $filePath = rtrim(str_replace("\\", "/", $filePath), "/") . "/";
     foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($filePath . "src")) as $file) {
         $path = ltrim(str_replace(["\\", $filePath], ["/", ""], $file), "/");
         if ($path[0] === "." or strpos($path, "/.") !== false or substr($path, 0, 4) !== "src/") {
             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[0]) or isset($args[0]) and $args[0] != "nogz") {
         $phar->compressFiles(\Phar::GZ);
     }
     $phar->stopBuffering();
     $sender->sendMessage($server->getName() . " " . $server->getPocketMineVersion() . "のpharファイルが" . $pharPath . "に生成されました");
     return true;
 }
Beispiel #25
0
 public function compile($pharFile = 'gisele.phar')
 {
     if (file_exists($pharFile)) {
         unlink($pharFile);
     }
     $p = new Process('git rev-parse HEAD', __DIR__);
     if (0 !== $p->run()) {
         throw new \RuntimeException('Unable to get current version, you must compile the phar from the Gisele git repository');
     }
     $this->version = trim($p->getOutput());
     $phar = new \Phar($pharFile, 0, 'gisele.phar');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     $finder = Finder::create()->files()->ignoreVCS(true)->name('*.php')->notName('PharCompiler.php')->in(__DIR__ . '/../');
     // Add src
     foreach ($finder as $file) {
         $path = str_replace(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR, '', $file->getRealPath());
         if (false !== strpos($path, 'Gisele.php')) {
             $content = str_replace('@version@', substr($this->version, 0, 8), file_get_contents($path));
             $phar->addFromString($path, $content);
         } else {
             $phar->addFile($path);
         }
     }
     $finder = Finder::create()->files()->ignoreVCS(true)->name('*.php')->exclude('Tests')->exclude('bin')->in(__DIR__ . '/../../vendor/fabpot/')->in(__DIR__ . '/../../vendor/guzzle/')->in(__DIR__ . '/../../vendor/symfony/')->in(__DIR__ . '/../../vendor/composer/');
     foreach ($finder as $file) {
         $path = str_replace(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR, '', $file->getRealPath());
         $phar->addFile($path);
     }
     $path = str_replace(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR, '', realpath(__DIR__ . '/../../vendor/autoload.php'));
     $phar->addFile($path);
     $content = file_get_contents(__DIR__ . '/../../bin/gisele');
     $content = preg_replace('{^#!/usr/bin/env php\\s*}', '', $content);
     $phar->addFromString('bin/gisele', $content);
     $phar->setStub($this->getStub());
     $phar->stopBuffering();
     unset($phar);
 }
Beispiel #26
0
 public function compile($pharFile = 'silex.phar')
 {
     if (file_exists($pharFile)) {
         unlink($pharFile);
     }
     $phar = new \Phar($pharFile, 0, 'Silex');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     $finder = new Finder();
     $finder->files()->name('*.php')->exclude('tests')->in(__DIR__ . '/..');
     foreach ($finder as $file) {
         $path = str_replace(realpath(__DIR__ . '/../..') . '/', '', realpath($file));
         $content = Kernel::stripComments(file_get_contents($file));
         $phar->addFromString($path, $content);
     }
     // Stubs
     $phar['_cli_stub.php'] = $this->getStub();
     $phar['_web_stub.php'] = $this->getStub();
     $phar->setDefaultStub('_cli_stub.php', '_web_stub.php');
     $phar->stopBuffering();
     // $phar->compressFiles(\Phar::GZ);
     unset($phar);
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $pharFile = $input->getOption('phar');
     $this->unlink($pharFile);
     $phar = new \Phar($pharFile, 0, 'php-cg.phar');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     $finder = new Finder();
     $finder->files('*.php')->exclude(array('test', 'build'))->in(array('src', 'vendor'));
     foreach ($finder as $file) {
         /* @var \Symfony\Component\Finder\SplFileInfo $file */
         $path = str_replace(dirname(realpath(__DIR__ . '/../../../../../php-cg')) . DIRECTORY_SEPARATOR, '', $file->getRealPath());
         $path = str_replace('\\', '/', $path);
         $phar->addFromString($path, file_get_contents($file->getRealPath()));
     }
     $phpCg = file_get_contents(__DIR__ . '/../../../../../php-cg');
     $phpCg = preg_replace('/^.*?(<\\?php.*)/ms', '\\1', $phpCg);
     $phar->addFromString('php-cg', $phpCg);
     $phar->setStub($this->getStub());
     $phar->stopBuffering();
     unset($phar);
     chmod($pharFile, 0777);
 }
 public function build($name)
 {
     retry:
     try {
         $this->randomName = generateRandomChars(16);
         $this->pharObj = new \Phar($this->pharPath = PUBLIC_DATA_PATH . $name . "." . $this->randomName . ".phar");
     } catch (\UnexpectedValueException $e) {
         $err = true;
     }
     if (isset($err)) {
         goto retry;
     }
     $this->pharObj->setStub('<?php __HALT_COMPILER();');
     $this->pharObj->setSignatureAlgorithm(\Phar::SHA512);
     $this->pharObj->startBuffering();
     $this->pharObj->addFile($this->extractionPluginPath . "plugin.yml", "plugin.yml");
     $this->addRecr($this->extractionPluginPath . "src", "src");
     if (is_dir($this->extractionPluginPath . "resources")) {
         $this->addRecr($this->extractionPluginPath . "resources", "resources");
     }
     $this->pharObj->compressFiles(\Phar::GZ);
     $this->pharObj->stopBuffering();
 }
<?php

$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
$alias = 'phar://' . $fname;
$phar = new Phar($fname);
$phar->setStub('<?php __HALT_COMPILER(); ?>');
$files = array();
$files['a.php'] = '<?php echo "This is a\\n"; ?>';
$files['b.php'] = '<?php echo "This is b\\n"; ?>';
$files['b/c.php'] = '<?php echo "This is b/c\\n"; ?>';
foreach ($files as $n => $file) {
    $phar[$n] = $file;
}
$phar->stopBuffering();
ini_set('phar.readonly', 1);
$fp = fopen($alias . '/b/new.php', 'wb');
fwrite($fp, 'extra');
fclose($fp);
include $alias . '/b/c.php';
include $alias . '/b/new.php';
?>

===DONE===
<?php 
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip');
<?php

$mindbody = new Phar("mboapi.phar");
$mindbody->startBuffering();
$files = new AppendIterator();
$files->append(new DirectoryIterator("services"));
$files->append(new DirectoryIterator("structures"));
$mindbody->buildFromIterator($files, dirname(__FILE__));
$mindbody->addFile("LICENSE");
$mindbody->addFile("README.markdown");
$mindbody->addFromString("loadServices.php", "<?php\n\tinclude_once(\"services/Appointment_Service.php\");\n\tinclude_once(\"services/Class_Service.php\");\n\tinclude_once(\"services/Client_Service.php\");\n\tinclude_once(\"services/Sale_Service.php\");\n\tinclude_once(\"services/Site_Service.php\");\n\tinclude_once(\"services/Staff_Service.php\");\n\tinclude_once(\"services/Data_Service.php\");\n\tinclude_once(\"services/Finder_Service.php\");\n?>");
$mindbody->setStub($mindbody->createDefaultStub("loadServices.php"));
$mindbody->stopBuffering();
foreach (new RecursiveIteratorIterator($mindbody) as $file) {
    echo $file->getFileName() . "\n";
}