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


PHP Phar::getPath方法代码示例

本文整理汇总了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);
    }
开发者ID:GoneTone,项目名称:web-server-source,代码行数:41,代码来源:Plugin.php

示例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);
开发者ID:PurePlugins,项目名称:PharUtils,代码行数:31,代码来源:PharExtractor.php

示例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();
开发者ID:zaky-92,项目名称:php-1,代码行数:31,代码来源:ext_phar_tests_badparameters.php

示例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;
    }
}
开发者ID:GoneTone,项目名称:web-server-source,代码行数:72,代码来源:functions.php


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