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;
}