本文整理汇总了PHP中Phar::getPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Phar::getPath方法的具体用法?PHP Phar::getPath怎么用?PHP Phar::getPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phar
的用法示例。
在下文中一共展示了Phar::getPath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: build
public function build()
{
$file = getTmpFile("phar");
$phar = new \Phar($file);
$phar->setStub("<?php __HALT_COMPILER(); ?>");
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
$namespace = "_{$this->name}" . randomClass(8, "\\_");
$class = randomClass(8);
$main = "{$namespace}\\{$class}";
$manifest = ["name" => $this->name, "version" => $this->version, "authors" => $this->authors, "api" => "1.9.0", "main" => $main, "commands" => []];
foreach ($this->cmds as $cmd) {
$manifest["commands"][$cmd->name] = ["description" => $cmd->desc, "usage" => $cmd->usage];
}
$phar->addFromString("plugin.yml", yaml_emit($manifest));
$mainClass = <<<EOS
<?php
namespace {$namespace};
use pocketmine\\command as cmd;
use pocketmine\\event as evt;
class {$class} extends \\pocketmine\\plugin\\PluginBase implements evt\\Listener{
public function onCommand(cmd\\CommandSender \$sender, cmd\\Command\\ \$cmd, \$lbl, array \$args){
switch(\$cmd->getName()){
EOS;
foreach ($this->cmds as $cmd) {
$mainClass .= "case " . var_export($cmd->name, true) . ":" . PHP_EOL;
$mainClass .= "return \$this->onCommand_{$cmd->name}(\$args, \$sender);" . PHP_EOL;
}
$mainClass .= "}" . PHP_EOL . "return false;" . PHP_EOL . "}" . PHP_EOL;
foreach ($this->cmds as $cmd) {
$mainClass .= $cmd->executor->toPhp();
}
$mainClass .= "}";
$phar->addFromString("src/" . str_replace("\\", "/", $main) . ".php", $mainClass);
// $phar->compressFiles(\Phar::GZ);
$phar->stopBuffering();
$path = $phar->getPath();
header("Content-Type: application/octet-stream");
echo file_get_contents($path);
// unlink($path);
}
示例2: exit
888 888 888P "Y88b d88 888 888 888 888 888 888 888
888888888888 888 888 8888888888 888 888 888 888 888 888
888 888 Y88b d88P 888 888 888 Y88b d88P Y88b d88P
888 888 "Y8888P" 888 888 888 "Y8888P" "Y8888P"
*/
echo "--- PharExtractor by #64FF00 --- \n \n";
if (!isset($argv[1]) || !file_exists($argv[1] . ".phar")) {
echo "[ERROR] Please specify a valid file name. \n \n";
exit(1);
}
if (pathinfo($argv[1], PATHINFO_EXTENSION) === "phar") {
$fileName = $argv[1];
} else {
$fileName = $argv[1] . ".phar";
}
$phar = new Phar($fileName);
$pharPath = "phar://" . $phar->getPath();
$currentDirectory = dirname($phar->getPath()) . DIRECTORY_SEPARATOR . $argv[1];
echo "[64FF00] Extracting files... Please wait... \n";
/** @var \SplFileInfo $splFileInfo */
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($pharPath)) as $splFileInfo) {
$tempFilePath = $currentDirectory . str_replace($pharPath, '', $splFileInfo->getPathname());
$tempDirectory = dirname($tempFilePath);
if (!file_exists($tempDirectory)) {
@mkdir($tempDirectory, 0755, true);
echo "[64FF00] New directory created: {$tempDirectory} \n";
}
file_put_contents($tempFilePath, file_get_contents($splFileInfo->getPathname()));
}
echo "[64FF00] Done! \n";
exit(0);
示例3: PharData
$c = new PharData(dirname(__FILE__) . '/whatever.zip');
} catch (PharException $e) {
print_exception($e);
}
$b->delete(array());
try {
$a->delete('oops');
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
try {
$b->delete('oops');
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
echo $a->getPath() . "\n";
try {
$a->setAlias('oops');
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
try {
$b->setAlias('oops');
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
ini_set('phar.readonly', 0);
$a->setAlias(array());
ini_set('phar.readonly', 1);
try {
$b->stopBuffering();
示例4: unphar_toZip
function unphar_toZip($tmpName, &$result, $name = "")
{
$result = ["tmpDir" => null, "zipPath" => null, "zipRelativePath" => null, "basename" => null, "error" => false];
rename($tmpName, "{$tmpName}.phar");
$tmpName .= ".phar";
try {
$phar = new Phar($tmpName);
$result["tmpDir"] = $tmpDir = getTmpDir();
$pharPath = "phar://{$phar->getPath()}/";
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($pharPath)) as $f) {
$subpath = substr($f, strlen($pharPath));
@mkdir(dirname($realSubpath = $tmpDir . $subpath), 0777, true);
copy($f, $realSubpath);
}
$zip = new ZipArchive();
$dir = "/data/phars/";
while (is_file($file = htdocs . ($rel = $dir . randomClass(16, "zip_" . $name . "_") . ".zip"))) {
}
$result["zipPath"] = $file;
$result["zipRelativePath"] = $rel;
$result["basename"] = substr($rel, 12);
$err = $zip->open($file, ZipArchive::CREATE);
if ($err !== true) {
$msg = "Error creating zip file: ";
switch ($err) {
case ZipArchive::ER_EXISTS:
$msg .= "ER_EXISTS ({$err}) File already exists ({$file})";
break;
case ZipArchive::ER_INCONS:
$msg .= "ER_INCONS ({$err}) Zip archive inconsistent.";
break;
case ZipArchive::ER_INVAL:
$msg .= "ER_INVAL ({$err}) Invalid argument.";
break;
case ZipArchive::ER_MEMORY:
$msg .= "ER_MEMORY ({$err}) Malloc failure.";
break;
case ZipArchive::ER_NOENT:
$msg .= "ER_NOENT ({$err}) No such file.";
break;
case ZipArchive::ER_NOZIP:
$msg .= "ER_NOZIP ({$err}) Not a zip archive.";
break;
case ZipArchive::ER_OPEN:
$msg .= "ER_OPEN ({$err}) Can't open file.";
break;
case ZipArchive::ER_READ:
$msg .= "ER_READ ({$err}) Read error.";
break;
case ZipArchive::ER_SEEK:
$msg .= "ER_SEEK ({$err}) Seek error.";
}
throw new RuntimeException($msg . " Dump: " . var_export($result, true));
}
$tmpDir = realpath($tmpDir);
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tmpDir)) as $file) {
if (!is_file($file)) {
continue;
}
$file = realpath($file);
$rel = substr($file, strlen($tmpDir) + 1);
$zip->addFile($file, str_replace("\\", "/", $rel));
}
$zip->setArchiveComment(json_encode($phar->getMetadata(), JSON_PRETTY_PRINT));
$zip->close();
} catch (Exception $e) {
echo "<pre>";
echo get_class($e) . ": {$e->getMessage()}";
echo "\r\n\tat {$e->getFile()}:{$e->getLine()}</pre>";
$result["error"] = true;
}
}