X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fpharext%2FInstaller.php;h=a90eb28e9acc97350465be252d22d20589568a3d;hb=337e76964be2ed6724633ac477affc3a28426c97;hp=4b90c49a0ae65ea7a133730c17e48242007261ef;hpb=861260c111bff72f60665393660b6f5375559510;p=pharext%2Fpharext diff --git a/src/pharext/Installer.php b/src/pharext/Installer.php index 4b90c49..a90eb28 100644 --- a/src/pharext/Installer.php +++ b/src/pharext/Installer.php @@ -15,6 +15,12 @@ class Installer implements Command { use CliCommand; + /** + * Cleanups + * @var array + */ + private $cleanup = []; + /** * Create the command */ @@ -38,32 +44,51 @@ class Installer implements Command "sudo -S %s"], ["i", "ini", "Activate in this php.ini instead of loaded default php.ini", CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::REQARG], + [null, "signature", "Show package signature", + CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG|CliArgs::HALT], + [null, "license", "Show package license", + CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG|CliArgs::HALT], + [null, "name", "Show package name", + CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG|CliArgs::HALT], + [null, "date", "Show package release date", + CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG|CliArgs::HALT], + [null, "release", "Show package release version", + CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG|CliArgs::HALT], + [null, "version", "Show pharext version", + CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG|CliArgs::HALT], ]); } + /** + * Perform cleaniup + */ + function __destruct() { + foreach ($this->cleanup as $cleanup) { + $cleanup->run(); + } + } + private function extract(Phar $phar) { - $this->debug("Extracting %s ...\n", basename($phar->getPath())); - return (new Task\Extract($phar))->run($this->args->verbose); + $temp = (new Task\Extract($phar))->run($this->verbosity()); + $this->cleanup[] = new Task\Cleanup($temp); + return $temp; } - + private function hooks(SplObjectStorage $phars) { - $hooks = []; + $hook = []; foreach ($phars as $phar) { - if (isset($phar["pharext_install.php"])) { - $callable = include $phar["pharext_install.php"]; - if (is_callable($callable)) { - $hooks[] = $callable($this); + if (isset($phar["pharext_package.php"])) { + $sdir = include $phar["pharext_package.php"]; + if ($sdir instanceof SourceDir) { + $this->args->compile($sdir->getArgs()); + $hook[] = $sdir; } } } - return $hooks; + return $hook; } - /** - * @inheritdoc - * @see \pharext\Command::run() - */ - public function run($argc, array $argv) { + private function load() { $list = new SplObjectStorage(); $phar = new Phar(Phar::running(false)); $temp = $this->extract($phar); @@ -75,11 +100,26 @@ class Installer implements Command $list[$dep_phar] = $this->extract($dep_phar); } } + /* the actual ext.phar at last */ $list[$phar] = $temp; + return $list; + } - /* installer hooks */ - $hook = $this->hooks($list); + /** + * @inheritdoc + * @see \pharext\Command::run() + */ + public function run($argc, array $argv) { + try { + /* load the phar(s) */ + $list = $this->load(); + /* installer hooks */ + $hook = $this->hooks($list); + } catch (\Exception $e) { + $this->error("%s\n", $e->getMessage()); + exit(self::EEXTRACT); + } /* standard arg stuff */ $errs = []; @@ -93,6 +133,17 @@ class Installer implements Command $this->help($prog); exit; } + try { + foreach (["signature", "name", "date", "license", "release", "version"] as $opt) { + if ($this->args[$opt]) { + printf("%s\n", $this->metadata($opt)); + exit; + } + } + } catch (\Exception $e) { + $this->error("%s\n", $e->getMessage()); + exit(self::EARGS); + } foreach ($this->args->validate() as $error) { $errs[] = $error; @@ -108,23 +159,30 @@ class Installer implements Command if (!$this->args["quiet"]) { $this->help($prog); } - exit(1); + exit(self::EARGS); } - /* post process hooks */ - foreach ($hook as $callback) { - if (is_callable($callback)) { - $callback($this); + try { + /* post process hooks */ + foreach ($hook as $sdir) { + $sdir->setArgs($this->args); } + } catch (\Exception $e) { + $this->error("%s\n", $e->getMessage()); + exit(self::EARGS); } /* install packages */ - foreach ($list as $phar) { - $this->info("Installing %s ...\n", basename($phar->getPath())); - $this->install($list[$phar]); - $this->activate($list[$phar]); - $this->cleanup($list[$phar]); - $this->info("Successfully installed %s!\n", basename($phar->getPath())); + try { + foreach ($list as $phar) { + $this->info("Installing %s ...\n", basename($phar->getPath())); + $this->install($list[$phar]); + $this->activate($list[$phar]); + $this->info("Successfully installed %s!\n", basename($phar->getPath())); + } + } catch (\Exception $e) { + $this->error("%s\n", $e->getMessage()); + exit(self::EINSTALL); } } @@ -132,40 +190,22 @@ class Installer implements Command * Phpize + trinity */ private function install($temp) { - try { - // phpize - $this->info("Running phpize ...\n"); - $phpize = new Task\Phpize($temp, $this->args->prefix, $this->args->{"common-name"}); - $phpize->run($this->args->verbose); - - // configure - $this->info("Running configure ...\n"); - $configure = new Task\Configure($temp, $this->args->configure, $this->args->prefix, $this->args{"common-name"}); - $configure->run($this->args->verbose); - - // make - $this->info("Running make ...\n"); - $make = new Task\Make($temp); - $make->run($this->args->verbose); - - // install - $this->info("Running make install ...\n"); - $sudo = isset($this->args->sudo) ? $this->args->sudo : null; - $install = new Task\Make($temp, ["install"], $sudo); - $install->run($this->args->verbose); - - } catch (\Exception $e) { - $this->error("%s\n", $e->getMessage()); - exit(2); - } - } + // phpize + $phpize = new Task\Phpize($temp, $this->args->prefix, $this->args->{"common-name"}); + $phpize->run($this->verbosity()); - private function cleanup($temp) { - if (is_dir($temp)) { - $this->rm($temp); - } elseif (file_exists($temp)) { - unlink($temp); - } + // configure + $configure = new Task\Configure($temp, $this->args->configure, $this->args->prefix, $this->args{"common-name"}); + $configure->run($this->verbosity()); + + // make + $make = new Task\Make($temp); + $make->run($this->verbosity()); + + // install + $sudo = isset($this->args->sudo) ? $this->args->sudo : null; + $install = new Task\Make($temp, ["install"], $sudo); + $install->run($this->verbosity()); } private function activate($temp) { @@ -177,17 +217,11 @@ class Installer implements Command } $sudo = isset($this->args->sudo) ? $this->args->sudo : null; - - try { - $this->info("Running INI activation ...\n"); - $activate = new Task\Activate($temp, $files, $sudo); - if (!$activate->run($this->args->verbose)) { - $this->info("Extension already activated ...\n"); - } - } catch (\Exception $e) { - $this->error("%s\n", $e->getMessage()); - $this->error("%s\n", $output); - exit(3); + $type = $this->metadata("type") ?: "extension"; + + $activate = new Task\Activate($temp, $files, $type, $this->args->prefix, $this->args{"common-name"}, $sudo); + if (!$activate->run($this->verbosity())) { + $this->info("Extension already activated ...\n"); } } }