From: Michael Wallner Date: Tue, 9 Apr 2019 06:45:44 +0000 (+0200) Subject: fix metadata retrieval when not running as phar X-Git-Tag: v4.1.2~3 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=3083798c97f453c3dbd5c9b16cf91846f69bb26f;p=pharext%2Fpharext fix metadata retrieval when not running as phar --- diff --git a/src/pharext/Cli/Command.php b/src/pharext/Cli/Command.php index 01c50c4..6b91aeb 100644 --- a/src/pharext/Cli/Command.php +++ b/src/pharext/Cli/Command.php @@ -3,6 +3,7 @@ namespace pharext\Cli; use pharext\Archive; +use pharext\Metadata; use Phar; @@ -10,7 +11,7 @@ trait Command { /** * Command line arguments - * @var pharext\Cli\Args + * @var Args */ private $args; @@ -28,21 +29,25 @@ trait Command * @return mixed */ public function metadata($key = null) { - if (extension_loaded("Phar")) { - $running = new Phar(Phar::running(false)); - } else { - $running = new Archive(PHAREXT_PHAR); - } + try { + if (extension_loaded("Phar")) { + $running = new Phar(Phar::running(false)); + } else { + $running = new Archive(PHAREXT_PHAR); + } - if ($key === "signature") { - $sig = $running->getSignature(); - return sprintf("%s signature of %s\n%s", - $sig["hash_type"], - $this->metadata("name"), - chunk_split($sig["hash"], 64, "\n")); - } + if ($key === "signature") { + $sig = $running->getSignature(); + return sprintf("%s signature of %s\n%s", + $sig["hash_type"], + $this->metadata("name"), + chunk_split($sig["hash"], 64, "\n")); + } - $metadata = $running->getMetadata(); + $metadata = $running->getMetadata(); + } catch (\Exception $e) { + $metadata = Metadata::all(); + } if (isset($key)) { return $metadata[$key]; }