/** * @param Package[]|string[]|string $packages * @param array $options * * @return bool */ public static function install($packages, array $options) { $options = array_merge(self::$options, $options); if (!Installer::isGravInstance($options['destination']) || !Installer::isValidDestination($options['destination'], [Installer::EXISTS, Installer::IS_LINK])) { return false; } $packages = is_array($packages) ? $packages : [$packages]; $count = count($packages); $packages = array_filter(array_map(function ($p) { return !is_string($p) ? $p instanceof Package ? $p : false : self::GPM()->findPackage($p); }, $packages)); if (!$options['skip_invalid'] && $count !== count($packages)) { return false; } $messages = ''; foreach ($packages as $package) { if (isset($package->dependencies) && $options['install_deps']) { $result = static::install($package->dependencies, $options); if (!$result) { return false; } } // Check destination Installer::isValidDestination($options['destination'] . DS . $package->install_path); if (Installer::lastErrorCode() === Installer::EXISTS && !$options['overwrite']) { return false; } if (Installer::lastErrorCode() === Installer::IS_LINK && !$options['ignore_symlinks']) { return false; } $license = Licenses::get($package->slug); $local = static::download($package, $license); Installer::install($local, $options['destination'], ['install_path' => $package->install_path, 'theme' => $options['theme']]); Folder::delete(dirname($local)); $errorCode = Installer::lastErrorCode(); if ($errorCode) { $msg = Installer::lastErrorMsg(); throw new \RuntimeException($msg); } if (count($packages) == 1) { $message = Installer::getMessage(); if ($message) { return $message; } else { $messages .= $message; } } } return $messages ?: true; }
public function license($package_slug) { return Licenses::get($package_slug); }
/** * @param $package * @param bool $is_update * * @return bool */ private function processGpm($package, $is_update = false) { $version = isset($package->available) ? $package->available : $package->version; $license = Licenses::get($package->slug); $this->output->writeln("Preparing to install <cyan>" . $package->name . "</cyan> [v" . $version . "]"); $this->output->write(" |- Downloading package... 0%"); $this->file = $this->downloadPackage($package, $license); if (!$this->file) { $this->output->writeln(" '- <red>Installation failed or aborted.</red>"); $this->output->writeln(''); return false; } $this->output->write(" |- Checking destination... "); $checks = $this->checkDestination($package); if (!$checks) { $this->output->writeln(" '- <red>Installation failed or aborted.</red>"); $this->output->writeln(''); } else { $this->output->write(" |- Installing package... "); $installation = $this->installPackage($package, $is_update); if (!$installation) { $this->output->writeln(" '- <red>Installation failed or aborted.</red>"); $this->output->writeln(''); } else { $this->output->writeln(" '- <green>Success!</green> "); $this->output->writeln(''); } } }