/** * save a file inside this package * @param string relative path within the package * @param string|resource file contents or open file handle */ function addFile($path, $fileOrStream) { if (!$this->_started) { // save package.xml name $this->phar->setMetadata($path); $this->_started = true; } $this->phar[$path] = $fileOrStream; }
/** * 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; }
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; }
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; }
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; }
* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ LICENSE; $file = 'psx-' . VERSION . '.phar'; $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(PATH), RecursiveIteratorIterator::SELF_FIRST); $phar = new Phar($file, 0, $file); $phar->setMetadata($license); foreach ($dir as $file) { $path = (string) $file; $name = substr($path, 12); // remove psx/library/ from path if ($file->isFile()) { $phar->addFromString($name, php_strip_whitespace($path)); } else { if ($file->isDir() && $file->getFilename() != '.' && $file->getFilename() != '..') { $phar->addEmptyDir($name); } } echo 'A ' . $name . "\n"; }
/** * Build and configure Phar object. * * @return Phar */ private function buildPhar() { $phar = new Phar($this->destinationFile); if (!empty($this->stubPath)) { $phar->setStub(file_get_contents($this->stubPath)); } else { if (!empty($this->cliStubFile)) { $cliStubFile = $this->cliStubFile->getPathWithoutBase($this->baseDirectory); } else { $cliStubFile = null; } if (!empty($this->webStubFile)) { $webStubFile = $this->webStubFile->getPathWithoutBase($this->baseDirectory); } else { $webStubFile = null; } $phar->setDefaultStub($cliStubFile, $webStubFile); } if ($this->metadata === null) { $this->createMetaData(); } if ($metadata = $this->metadata->toArray()) { $phar->setMetadata($metadata); } if (!empty($this->alias)) { $phar->setAlias($this->alias); } return $phar; }
header("Content-Type: text/plain"); $input = json_decode(file_get_contents("php://input"), true); if (getallheaders()["X-GitHub-Event"] === "push") { $startTime = microtime(true); /* $archives = $input["repository"]["archive_url"]; $url = str_replace(["{archive_format}", "{/ref}"], ["zipball", ""], $archives); $rawData = getURL($url); $zipPath = tempnam("", "zip"); file_put_contents($zipPath, $rawData); $zip = new ZipArchive; $zip->open($zipPath);*/ $path = "/var/www/html/releases/ImagicalMine.phar"; @unlink($path); $phar = new Phar($path); $phar->setMetadata(["name" => "ImagicalMine", "version" => "#" . substr($input["after"], 0, 7), "api" => "1.13.0", "minecraft" => "0.13.0", "protocol" => 38, "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(); /*$cnt = 1; for($i = 0; $i < $zip->numFiles; $i++){ $name = $zip->getNameIndex($i); if(strpos($name, "src/") === 27 and substr($name, -1) !== "/"){ $phar->addFromString($name = substr($name, 27), $buffer = $zip->getFromIndex($i)); echo "[" . (++$cnt) . "] Adding " . round(strlen($buffer) / 1024, 2) . " KB to /$name", PHP_EOL; } }*/ chdir("/ImagicalMine"); echo `git pull --no-edit --recurse-submodules`; //$phar->buildFromDirectory("/ImagicalMine"); foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator("/ImagicalMine/src")) as $file) {
/** * Build and configure Phar object. * * @return Phar */ private function buildPhar() { $phar = new Phar($this->destinationFile); $phar->setSignatureAlgorithm($this->signatureAlgorithm); if (isset($this->stubPath)) { $phar->setStub(file_get_contents($this->stubPath)); } else { $phar->setDefaultStub($this->cliStubFile->getPathWithoutBase($this->baseDirectory), $this->webStubFile->getPathWithoutBase($this->baseDirectory)); } if ($metadata = $this->metadata->toArray()) { $phar->setMetadata($metadata); } if (!empty($this->alias)) { $phar->setAlias($this->alias); } return $phar; }
<?php $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar.php'; $pname = 'phar://' . $fname; $fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.tar.php'; $pname2 = 'phar://' . $fname2; $phar = new Phar($fname); $phar->setMetadata('hi there'); $phar['a'] = 'hi'; $phar['a']->setMetadata('a meta'); $phar['b'] = 'hi2'; $phar['c'] = 'hi3'; $phar['b']->chmod(0444); $phar->setStub("<?php ok __HALT_COMPILER();"); $phar->setAlias("hime"); unset($phar); copy($fname, $fname2); Phar::unlinkArchive($fname); var_dump(file_exists($fname), file_exists($pname . '/a')); $phar = new Phar($fname2); var_dump($phar['a']->getContent(), $phar['b']->getContent(), $phar['c']->getContent()); var_dump((string) decoct(fileperms($pname2 . '/b'))); var_dump($phar->getStub()); var_dump($phar->getAlias()); var_dump($phar->getMetadata()); var_dump($phar['a']->getMetadata()); ?> ===DONE=== <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.tar.php');
// normalize newlines to \n $whitespace = preg_replace('{(?:\\r\\n|\\r|\\n)}', "\n", $whitespace); // trim leading spaces $whitespace = preg_replace('{\\n +}', "\n", $whitespace); $output .= $whitespace; } else { $output .= $token[1]; } } } return $output; }; $pharObj = new \Phar($phar, 0); $pharObj->setSignatureAlgorithm(\Phar::SHA1); $pharObj->addFromString('version', $version); $pharObj->setMetadata(array('version' => $version)); $pharObj->startBuffering(); foreach ($finders as $finder) { /** @var $file \SplFileInfo */ foreach ($finder as $file) { if (pathinfo($file->getPathname(), PATHINFO_EXTENSION) === 'php') { $source = file_get_contents($file->getPathname()); $source = $stripWhitespace($source); $pharObj->addFromString($file->getPathname(), $source); echo "* " . $file->getPathname() . "\n"; } else { $pharObj->addFile($file->getPathname()); echo " " . $file->getPathname() . "\n"; } } }
} $a->offsetExists(array()); $a->offsetGet(array()); ini_set('phar.readonly', 0); $a->offsetSet(array()); ini_set('phar.readonly', 1); $b->offsetUnset(array()); try { $a->offsetUnset('a'); } catch (Exception $e) { echo $e->getMessage() . "\n"; } $a->addEmptyDir(array()); $a->addFile(array()); $a->addFromString(array()); try { $a->setMetadata('a'); } catch (Exception $e) { echo $e->getMessage() . "\n"; } ini_set('phar.readonly', 0); $a->setMetadata(1, 2); ini_set('phar.readonly', 1); try { $a->delMetadata(); } catch (Exception $e) { echo $e->getMessage() . "\n"; } ?> ===DONE===
/** * Build the Phar * * @param string $workspace * @param array $args * @return bool */ protected function buildPhar(string $workspace, array $args = []) : bool { $this->setupFiles($workspace, $args); // We don't need this to be random: $this->pharname = 'airship-' . \date('YmdHis') . '.phar'; $phar = new \Phar(AIRSHIP_LOCAL_CONFIG . DIRECTORY_SEPARATOR . $this->pharname, \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::KEY_AS_FILENAME, $this->pharAlias); $phar->buildFromDirectory($workspace); $metaData = $this->getRawMetadata(); $metaData['commit'] = $this->getGitCommitHash(); $phar->setMetadata($metaData); echo 'Built at: ', AIRSHIP_LOCAL_CONFIG . DIRECTORY_SEPARATOR . $this->pharname, "\n"; echo 'Git commit for this build: ', $metaData['commit'], "\n"; return $this->cleanupWorkspace($workspace); }
/** * Build and configure Phar object. * * @return Phar */ private function buildPhar() { $phar = new Phar($this->destinationFile); if ($this->signatureAlgorithm == Phar::OPENSSL) { // Load up the contents of the key $keyContents = file_get_contents($this->key); // Attempt to load the given key as a PKCS#12 Cert Store first. if (openssl_pkcs12_read($keyContents, $certs, $this->keyPassword)) { $private = openssl_pkey_get_private($certs['pkey']); } else { // Fall back to a regular PEM-encoded private key. // Setup an OpenSSL resource using the private key // and tell the Phar to sign it using that key. $private = openssl_pkey_get_private($keyContents, $this->keyPassword); } $phar->setSignatureAlgorithm(Phar::OPENSSL, $private); // Get the details so we can get the public key and write that out // alongside the phar. $details = openssl_pkey_get_details($private); file_put_contents($this->destinationFile . '.pubkey', $details['key']); } else { $phar->setSignatureAlgorithm($this->signatureAlgorithm); } if (!empty($this->stubPath)) { $phar->setStub(file_get_contents($this->stubPath)); } else { if (!empty($this->cliStubFile)) { $cliStubFile = $this->cliStubFile->getPathWithoutBase($this->baseDirectory); } else { $cliStubFile = null; } if (!empty($this->webStubFile)) { $webStubFile = $this->webStubFile->getPathWithoutBase($this->baseDirectory); } else { $webStubFile = null; } $phar->setDefaultStub($cliStubFile, $webStubFile); } if ($this->metadata === null) { $this->createMetaData(); } if ($metadata = $this->metadata->toArray()) { $phar->setMetadata($metadata); } if (!empty($this->alias)) { $phar->setAlias($this->alias); } return $phar; }
/** * Build a Gadget * * @param string $path * @param array $manifest */ protected function buildGadget(string $path, array $manifest = []) { // Step One -- Let's build our .phar file $pharName = $manifest['supplier'] . '.' . $manifest['name'] . '.phar'; try { if (\file_exists($path . '/dist/' . $pharName)) { \unlink($path . '/dist/' . $pharName); \clearstatcache(); } if (\file_exists($path . '/dist/' . $pharName . '.ed25519.sig')) { \unlink($path . '/dist/' . $pharName . '.ed25519.sig'); \clearstatcache(); } $phar = new \Phar($path . '/dist/' . $pharName, \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::KEY_AS_FILENAME, $pharName); } catch (\UnexpectedValueException $e) { echo 'Could not open .phar', "\n"; exit(255); // Return an error flag } $phar->buildFromDirectory($path); $phar->setStub($phar->createDefaultStub('autoload.php', 'autoload.php')); $phar->setMetadata($manifest); echo 'Gadget built.', "\n", $path . '/dist/' . $pharName, "\n", 'Don\'t forget to sign it!', "\n"; exit(0); // Return a success flag }
unset($temp[0], $temp[1]); $get_params = array(); foreach ($temp as $k => $v) { $get_params[] = strpos($v, '=') !== false ? $v : $v . '='; } $params = array(); parse_str(implode('&', $get_params), $params); // version if ($command == 'version') { echo "Numbers Installer: version 1.0.0\n"; exit; } // if we need to make numbers.phar file if ($command == '--build-phar-file') { $phar = new Phar(dirname(__FILE__) . '/../build/numbers.phar', 0, 'numbers.phar'); $phar->buildFromDirectory(dirname(__FILE__) . '/../src/'); $phar->setStub($phar->createDefaultStub('installer.php')); $phar->setMetadata(array('timestamp' => time())); chmod(dirname(__FILE__) . '/../build/numbers.phar', 0777); exit; } // available commands $commands = array('new_application', 'code_cleaner'); // redirecting to command handler if (in_array($command, $commands)) { echo "Numbers Installer: entering {$command} action.\n"; require_once "phar://numbers.phar/lib/functions.php"; require_once "phar://numbers.phar/lib/{$command}.php"; } else { echo "Numbers Installer: Unknown command!\n"; }
/** * Build and configure Phar object. * * @return Phar */ private function buildPhar() { $phar = new Phar($this->destinationFile); $phar->setSignatureAlgorithm($this->signatureAlgorithm); /* * File compression, if needed. */ if (Phar::NONE != $this->compression) { $phar->compressFiles($this->compression); } $phar->setDefaultStub($this->cliStubFile, $this->webStubFile); if ($metadata = $this->metadata->toArray()) { $phar->setMetadata($metadata); } return $phar; }
// default meta information $metaData = array('Author' => 'Mark Baker <*****@*****.**>', 'Description' => 'A Geodetic library', 'Copyright' => 'Mark Baker (c) 2012-' . date('Y'), 'Timestamp' => time(), 'Version' => '0.2', 'Date' => date('Y-m-d')); // cleanup if (file_exists($pharName)) { echo "Removed: {$pharName}\n"; unlink($pharName); } echo "Building phar file...\n"; // the phar object $phar = new Phar($pharName, null, 'Geodetic'); $phar->buildFromDirectory($sourceDir); $phar->setStub(<<<'EOT' <?php spl_autoload_register(function ($className) { include 'phar://' . str_replace('\\', '/', $className) . '.php'; }); try { Phar::mapPhar(); } catch (PharException $e) { error_log($e->getMessage()); exit(1); } __HALT_COMPILER(); EOT ); $phar->setMetadata($metaData); $phar->compressFiles(Phar::GZ); echo "Complete.\n"; exit;
/** * Build and configure Phar object. * * @return Phar */ private function buildPhar() { $phar = new Phar($this->destinationFile, 0, $this->alias); $phar->setSignatureAlgorithm($this->signatureAlgorithm); /* * File compression, if needed. */ if (Phar::NONE != $this->compression) { $phar->compressFiles($this->compression); } if (isset($this->customStubPath)) { $phar->setStub(file_get_contents($this->customStubPath)); } else { $phar->setDefaultStub($this->cliStubFile, $this->webStubFile); } if ($metadata = $this->metadata->toArray()) { $phar->setMetadata($metadata); } if (!empty($this->alias)) { $phar->setAlias($this->alias); } return $phar; }
<?php $p = new Phar(__FILE__); var_dump($p->getMetadata()); $p->setMetadata("hi"); var_dump($p->getMetadata()); echo "ok\n"; __halt_compiler(); ?> 6test.txt���H���E�<?php __HALT_COMPILER();~�bp�DZNu�@.�]GBMB
public function makePharPlugin($pluginName) { if ($pluginName === "" or !($plugin = $this->getServer()->getPluginManager()->getPlugin($pluginName)) instanceof Plugin) { $this->getLogger()->alert("잘못된 플러그인 이름, 이름을 다시 확인해주세요"); return; } $description = $plugin->getDescription(); if (!$plugin->getPluginLoader() instanceof FolderPluginLoader) { $this->getLogger()->alert("플러그인 " . $description->getName() . " 은 이미 PHAR 상태입니다."); return; } $pharPath = $this->getServer()->getDataPath() . "localhost" . DIRECTORY_SEPARATOR . $pluginName . DIRECTORY_SEPARATOR . $description->getName() . "-release" . ".phar"; if (file_exists($pharPath)) { $this->getLogger()->info("Phar 파일 덮어쓰기중..."); \Phar::unlinkArchive($pharPath); } $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->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(array("\\", $filePath), array("/", ""), $file), "/"); if ($path[0] === "." or strpos($path, "/.") !== false) { continue; } $phar->addFile($file, $path); } $phar->compressFiles(\Phar::GZ); $phar->stopBuffering(); $this->getLogger()->info("PHAR이 해당 플러그인 소스폴더 안에 생성되었습니다. "); $this->getLogger()->info("( " . $pharPath . " )"); }
date_default_timezone_set("UTC"); print "Packaging plugin...\n"; $description = file_get_contents(DIRECTORY . "/plugin.yml"); preg_match_all("/name:(.*)/", $description, $matches); $name = $matches[1][0]; preg_match_all("/main:(.*)/", $description, $matches); $main = $matches[1][0]; preg_match_all("/version:(.*)/", $description, $matches); $version = $matches[1][0]; preg_match_all("/api:(.*)/", $description, $matches); $api = $matches[1][0]; preg_match_all("/website:(.*)/", $description, $matches); $website = $matches[1][0]; $pharPath = DIRECTORY . "/" . $name . "_v" . $version . ".phar"; $phar = new Phar($pharPath); $phar->setMetadata(array("name" => $name, "version" => $version, "main" => $main, "api" => $api, "website" => $website, "creationDate" => strtotime("now"))); $phar->setStub('<?php echo "PocketMine-MP plugin ' . $name . ' v' . $version . '\\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(); $filePath = DIRECTORY; foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($filePath)) as $file) { $path = ltrim(str_replace(array("\\", $filePath), array("/", ""), $file), "/"); if ($path[0] === "." || strpos($path, "/.") !== false || $path === $pharPath) { continue; } print "Adding {$path}\n"; $phar->addFile($file, $path); } $phar->compressFiles(\Phar::GZ); $phar->stopBuffering(); print "Plugin packaged.\n";
/** * Build and configure Phar object. * * @return Phar */ private function buildPhar() { $phar = new Phar($this->destinationFile); if ($this->signatureAlgorithm == Phar::OPENSSL) { // Load up the contents of the key $keyContents = file_get_contents($this->key); // Setup an OpenSSL resource using the private key and tell the Phar // to sign it using that key. $private = openssl_pkey_get_private($keyContents, $this->keyPassword); $phar->setSignatureAlgorithm(Phar::OPENSSL, $private); // Get the details so we can get the public key and write that out // alongside the phar. $details = openssl_pkey_get_details($private); file_put_contents($this->destinationFile . '.pubkey', $details['key']); } else { $phar->setSignatureAlgorithm($this->signatureAlgorithm); } if (isset($this->stubPath)) { $phar->setStub(file_get_contents($this->stubPath)); } else { if (!empty($this->cliStubFile)) { $cliStubFile = $this->cliStubFile->getPathWithoutBase($this->baseDirectory); } else { $cliStubFile = null; } if (!empty($this->webStubFile)) { $webStubFile = $this->webStubFile->getPathWithoutBase($this->baseDirectory); } else { $webStubFile = null; } $phar->setDefaultStub($cliStubFile, $webStubFile); } if ($metadata = $this->metadata->toArray()) { $phar->setMetadata($metadata); } if (!empty($this->alias)) { $phar->setAlias($this->alias); } return $phar; }
$localPath = rtrim($localPath, "/\\") . "/"; echo "Directory transfer: {$realPath} > {$localPath}", PHP_EOL; foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($realPath)) as $path) { if (!$path->isFile()) { continue; } $path = str_replace("\\", "/", (string) $path); if (strpos($path, ".git") !== false) { continue; } $relative = ltrim(substr($path, strlen($realPath)), "/"); $local = $localPath . $relative; $num = str_pad((string) ++$i, 3, "0", STR_PAD_LEFT); echo "\r[{$num}] Adding: " . realpath($path) . " to {$local}"; $phar->addFile($path, $local); } echo "\n"; } $phar = new Phar($filename); $phar->setStub('<?php require_once "entry/entry.php"; __HALT_COMPILER();'); $phar->setSignatureAlgorithm(Phar::SHA1); $phar->setMetadata($manifest); $phar->startBuffering(); $phar->addFromString("plugin.yml", $pluginYml); $phar->addFromString("resources/meta.build.json", json_encode($buildData, JSON_UNESCAPED_SLASHES | JSON_BIGINT_AS_STRING)); addDir($phar, realpath("src"), "src"); addDir($phar, realpath("resources"), "resources"); $phar->stopBuffering(); if (is_file("priv\\postCompile.php")) { require_once "priv\\postCompile.php"; }
888 888 Y88b d88P 888 888 888 Y88b d88P Y88b d88P 888 888 "Y8888P" 888 888 888 "Y8888P" "Y8888P" */ echo "--- PharBuilder by #64FF00 --- \n \n"; if (!isset($argv[1]) || !is_dir($argv[1])) { echo "[ERROR] Please specify a valid directory name. \n \n"; exit(1); } $filePath = $argv[1] . ".phar"; if (file_exists($filePath)) { @unlink($filePath); } $phar = new Phar($filePath); $phar->startBuffering(); echo "[64FF00] Setting custom Phar archive metadata... \n"; $phar->setMetadata(["name" => $argv[1], "creationDate" => time()]); /* * DevTools: require("phar://". __FILE__ ."/src/DevTools/ConsoleScript.php"); */ $phar->setStub('<?php echo "Hello, world! \\n This PHAR archive has been generated using PharBuilder by #64FF00! :D"; __HALT_COMPILER();'); $phar->setSignatureAlgorithm(Phar::SHA512); /** @var \SplFileInfo $splFileInfo */ foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($argv[1])) as $splFileInfo) { $tempDirectory = str_replace($argv[1], '', $splFileInfo->getPathname()); if ($splFileInfo->getFilename() === '.' || $splFileInfo->getFilename() === '..') { continue; } echo "[64FF00] Adding file: " . $splFileInfo->getPathname() . "\n"; $phar->addFile($splFileInfo->getPathname(), $tempDirectory); } echo "[64FF00] Compressing files... \n";
private function makeServerCommand(CommandSender $sender, Command $command, $label, array $args) { $server = $sender->getServer(); $pharPath = $this->getDataFolder() . 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(), "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(["\\", $filePath], ["/", ""], $file), "/"); if ($path[0] === "." or strpos($path, "/.") !== false or substr($path, 0, 4) !== "src/") { continue; } $phar->addFile($file, $path); $sender->sendMessage("[DevTools] 添加 {$path}"); } foreach ($phar as $file => $finfo) { /** @var \PharFileInfo $finfo */ if ($finfo->getSize() > 1024 * 512) { $finfo->compress(\Phar::GZ); } } $phar->stopBuffering(); $sender->sendMessage($server->getName() . " " . $server->getPocketMineVersion() . " Phar文件已創建 " . $pharPath); return true; }
<?php $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; $fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.php'; if (file_exists($fname)) { unlink($fname); } if (file_exists($fname2)) { unlink($fname2); } $phar = new Phar($fname); // no entries, never flushed $phar->setAlias('first'); $phar->setMetadata('hi'); unset($phar); $phar = new Phar($fname2); $phar['b'] = 'whatever'; // flushed try { $phar->setAlias('first'); } catch (Exception $e) { echo $e->getMessage() . "\n"; } $phar = new Phar($fname); var_dump($phar->getMetadata()); var_dump($phar->getAlias()); var_dump(file_exists($fname)); ?> ===DONE=== <?php error_reporting(0);
$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; $pname = 'phar://' . $fname; $file = "<?php __HALT_COMPILER(); ?>"; $files = array(); $files['a'] = array('cont' => 'a'); $files['b'] = array('cont' => 'b', 'meta' => 'hi there'); $files['c'] = array('cont' => 'c', 'meta' => array('hi', 'there')); $files['d'] = array('cont' => 'd', 'meta' => array('hi' => 'there', 'foo' => 'bar')); include 'files/phar_test.inc'; foreach ($files as $name => $cont) { var_dump(file_get_contents($pname . '/' . $name)); } $phar = new Phar($fname); var_dump($phar->getMetadata()); $phar->setMetadata(array('my' => 'friend')); $phar->setMetadata(array('my' => 'friend')); var_dump($phar->getMetadata()); $phar['a']->setMetadata(42); $phar['b']->setMetadata(NULL); $phar['c']->setMetadata(array(25, 'foo' => 'bar')); $phar['d']->setMetadata(true); foreach ($files as $name => $cont) { var_dump($phar[$name]->getMetadata()); } unset($phar); foreach ($files as $name => $cont) { var_dump(file_get_contents($pname . '/' . $name)); } ?> ===DONE===
<?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; }
$name = $_SERVER['argv'][1]; } else { $name = 'Hoa.phar'; } if (file_exists($name) && false === unlink($name)) { throw new Hoa\Core\Exception('Phar %s already exists and we cannot delete it.', 1, $name); } class Filter extends FilterIterator { public function accept() { return false === strpos($this->current()->getPathname(), '.git'); } } $phar = new Phar(__DIR__ . DS . $name); $phar->setMetadata(['author' => 'Ivan Enderlin, Hoa community', 'license' => 'New BSD License', 'copyright' => \Hoa\Core::©(), 'version.name' => $name, 'datetime' => date('c')]); $phar->setSignatureAlgorithm(Phar::SHA1); $phar->buildFromIterator(new Filter(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root))), $root); $phar->setStub(<<<'STUB' <?php Phar::mapPhar('Hoa.phar'); require 'phar://Hoa.phar/Core/Core.php'; $phar = new Phar(__FILE__); foreach (array_slice($_SERVER['argv'], 1) ?: ['-h'] as $option) { switch (strtolower($option)) { case '-m': case '--metadata': echo 'Metadata:' . "\n\n";