6 use pharext\Cli\Args
as CliArgs
;
10 if (!function_exists("array_column")) {
11 function array_column(array $array, $col, $idx = null) {
13 foreach ($array as $el) {
15 $result[$el[$idx]] = $el[$col];
17 $result[] = $el[$col];
27 * Command line arguments
28 * @var pharext\CliArgs
34 * @see \pharext\Command::getArgs()
36 public function getArgs() {
41 * Retrieve metadata of the currently running phar
45 public function metadata($key = null) {
46 if (extension_loaded("Phar")) {
47 $running = new Phar(Phar
::running(false));
49 $running = new Archive(PHAREXT_PHAR
);
52 if ($key === "signature") {
53 $sig = $running->getSignature();
54 return sprintf("%s signature of %s\n%s",
56 $this->metadata("name"),
57 chunk_split($sig["hash"], 64, "\n"));
60 $metadata = $running->getMetadata();
62 return $metadata[$key];
68 * Output pharext vX.Y.Z header
70 public function header() {
71 if (!headers_sent()) {
72 /* only display header, if we didn't generate any output yet */
73 printf("%s\n\n", $this->metadata("header"));
79 * @see \pharext\Command::debug()
81 public function debug($fmt) {
82 if ($this->args
->verbose
) {
83 vprintf($fmt, array_slice(func_get_args(), 1));
89 * @see \pharext\Command::info()
91 public function info($fmt) {
92 if (!$this->args
->quiet
) {
93 vprintf($fmt, array_slice(func_get_args(), 1));
99 * @see \pharext\Command::warn()
101 public function warn($fmt) {
102 if (!$this->args
->quiet
) {
105 $arg = error_get_last()["message"];
107 $arg = array_slice(func_get_args(), 1);
109 vfprintf(STDERR
, "Warning: $fmt", $arg);
115 * @see \pharext\Command::error()
117 public function error($fmt) {
120 $arg = error_get_last()["message"];
122 $arg = array_slice(func_get_args(), 1);
124 vfprintf(STDERR
, "ERROR: $fmt", $arg);
128 * Output command line help message
129 * @param string $prog
131 public function help($prog) {
132 print new Args\
Help($prog, $this->args
);
139 public function verbosity() {
140 if ($this->args
->verbose
) {
142 } elseif ($this->args
->quiet
) {