本文整理汇总了PHP中Composer\Installer类的典型用法代码示例。如果您正苦于以下问题:PHP Installer类的具体用法?PHP Installer怎么用?PHP Installer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Installer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* {@inheritdoc}
*/
public function handle(\Input $input)
{
if ($input->post('FORM_SUBMIT') == 'tl_composer_migrate_undo') {
/** @var RootPackage $rootPackage */
$rootPackage = $this->composer->getPackage();
$requires = $rootPackage->getRequires();
foreach (array_keys($requires) as $package) {
if ($package != 'contao-community-alliance/composer') {
unset($requires[$package]);
}
}
$rootPackage->setRequires($requires);
$lockPathname = preg_replace('#\\.json$#', '.lock', $this->configPathname);
/** @var DownloadManager $downloadManager */
$downloadManager = $this->composer->getDownloadManager();
$downloadManager->setOutputProgress(false);
$installer = Installer::create($this->io, $this->composer);
if (file_exists(TL_ROOT . '/' . $lockPathname)) {
$installer->setUpdate(true);
}
if ($installer->run()) {
$_SESSION['COMPOSER_OUTPUT'] .= $this->io->getOutput();
} else {
$_SESSION['COMPOSER_OUTPUT'] .= $this->io->getOutput();
$this->redirect('contao/main.php?do=composer&migrate=undo');
}
// load config
$json = new JsonFile(TL_ROOT . '/' . $this->configPathname);
$config = $json->read();
// remove migration status
unset($config['extra']['contao']['migrated']);
// write config
$json->write($config);
// disable composer client and enable repository client
$inactiveModules = deserialize($GLOBALS['TL_CONFIG']['inactiveModules']);
$inactiveModules[] = '!composer';
foreach (array('rep_base', 'rep_client', 'repository') as $module) {
$pos = array_search($module, $inactiveModules);
if ($pos !== false) {
unset($inactiveModules[$pos]);
}
}
if (version_compare(VERSION, '3', '>=')) {
$skipFile = new \File('system/modules/!composer/.skip');
$skipFile->write('Remove this file to enable the module');
$skipFile->close();
}
if (file_exists(TL_ROOT . '/system/modules/repository/.skip')) {
$skipFile = new \File('system/modules/repository/.skip');
$skipFile->delete();
}
$this->Config->update("\$GLOBALS['TL_CONFIG']['inactiveModules']", serialize($inactiveModules));
$this->redirect('contao/main.php?do=repository_manager');
}
$template = new \BackendTemplate('be_composer_client_migrate_undo');
$template->composer = $this->composer;
$template->output = $_SESSION['COMPOSER_OUTPUT'];
unset($_SESSION['COMPOSER_OUTPUT']);
return $template->parse();
}
示例2: execute
/**
* Executes composer for the extension.
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$name = $this->argument('extension');
$update = $this->option('update');
if (!is_dir($path = $this->pagekit['path.extensions'] . "/{$name}") && file_exists("{$path}/extension.json")) {
$this->error("Extension not exists '{$path}'");
exit;
}
$package = json_decode(file_get_contents("{$path}/extension.json"), true);
if (!isset($package['composer']) || empty($package['composer'])) {
$this->error("Composer not defined in '{$path}/extension.json'");
exit;
}
$this->loadComposer($path);
$io = new ConsoleIO($input, $output, $this->getHelperSet());
$composer = Factory::create($io, $package['composer']);
$lockFile = new JsonFile("{$path}/extension.lock");
$locker = new Locker($io, $lockFile, $composer->getRepositoryManager(), $composer->getInstallationManager(), md5(json_encode($package['composer'])));
$composer->setLocker($locker);
$installed = new JsonFile($this->pagekit['path'] . '/vendor/composer/installed.json');
$internal = new CompositeRepository([]);
$internal->addRepository(new InstalledFilesystemRepository($installed));
$installer = Installer::create($io, $composer);
$installer->setAdditionalInstalledRepository($internal);
$installer->setUpdate($update);
return $installer->run();
}
示例3: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$factory = new Factory();
$file = $factory->getComposerFile();
if (!file_exists($file)) {
$output->writeln('<error>' . $file . ' not found.</error>');
return 1;
}
if (!is_readable($file)) {
$output->writeln('<error>' . $file . ' is not readable.</error>');
return 1;
}
$dialog = $this->getHelperSet()->get('dialog');
$json = new JsonFile($file);
$composer = $json->read();
$requirements = $this->determineRequirements($input, $output, $input->getArgument('packages'));
$requireKey = $input->getOption('dev') ? 'require-dev' : 'require';
$baseRequirements = array_key_exists($requireKey, $composer) ? $composer[$requireKey] : array();
$requirements = $this->formatRequirements($requirements);
if (!$this->updateFileCleanly($json, $baseRequirements, $requirements, $requireKey)) {
foreach ($requirements as $package => $version) {
$baseRequirements[$package] = $version;
}
$composer[$requireKey] = $baseRequirements;
$json->write($composer);
}
$output->writeln('<info>' . $file . ' has been updated</info>');
// Update packages
$composer = $this->getComposer();
$io = $this->getIO();
$install = Installer::create($io, $composer);
$install->setVerbose($input->getOption('verbose'))->setPreferSource($input->getOption('prefer-source'))->setDevMode($input->getOption('dev'))->setUpdate(true)->setUpdateWhitelist($requirements);
return $install->run() ? 0 : 1;
}
示例4: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$composer = $this->getComposer();
$composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
$io = $this->getIO();
$install = Installer::create($io, $composer);
$preferSource = false;
$preferDist = false;
switch ($composer->getConfig()->get('preferred-install')) {
case 'source':
$preferSource = true;
break;
case 'dist':
$preferDist = true;
break;
case 'auto':
default:
// noop
break;
}
if ($input->getOption('prefer-source') || $input->getOption('prefer-dist')) {
$preferSource = $input->getOption('prefer-source');
$preferDist = $input->getOption('prefer-dist');
}
$install->setDryRun($input->getOption('dry-run'))->setVerbose($input->getOption('verbose'))->setPreferSource($preferSource)->setPreferDist($preferDist)->setDevMode($input->getOption('dev'))->setRunScripts(!$input->getOption('no-scripts'))->setOptimizeAutoloader($input->getOption('optimize-autoloader'));
if ($input->getOption('no-custom-installers')) {
$install->disableCustomInstallers();
}
return $install->run() ? 0 : 1;
}
示例5: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('no-custom-installers')) {
$output->writeln('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
$input->setOption('no-plugins', true);
}
$composer = $this->getComposer(true, $input->getOption('no-plugins'));
$composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
$io = $this->getIO();
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'install', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
$install = Installer::create($io, $composer);
$preferSource = false;
$preferDist = false;
switch ($composer->getConfig()->get('preferred-install')) {
case 'source':
$preferSource = true;
break;
case 'dist':
$preferDist = true;
break;
case 'auto':
default:
break;
}
if ($input->getOption('prefer-source') || $input->getOption('prefer-dist')) {
$preferSource = $input->getOption('prefer-source');
$preferDist = $input->getOption('prefer-dist');
}
$install->setDryRun($input->getOption('dry-run'))->setVerbose($input->getOption('verbose'))->setPreferSource($preferSource)->setPreferDist($preferDist)->setDevMode(!$input->getOption('no-dev'))->setRunScripts(!$input->getOption('no-scripts'))->setOptimizeAutoloader($input->getOption('optimize-autoloader'));
if ($input->getOption('no-plugins')) {
$install->disablePlugins();
}
return $install->run();
}
示例6: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = $this->getIO();
if ($args = $input->getArgument('packages')) {
$io->writeError('<error>Invalid argument ' . implode(' ', $args) . '. Use "composer require ' . implode(' ', $args) . '" instead to add packages to your composer.json.</error>');
return 1;
}
if ($input->getOption('no-custom-installers')) {
$io->writeError('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
$input->setOption('no-plugins', true);
}
if ($input->getOption('dev')) {
$io->writeError('<warning>You are using the deprecated option "dev". Dev packages are installed by default now.</warning>');
}
$composer = $this->getComposer(true, $input->getOption('no-plugins'));
$composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'install', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
$install = Installer::create($io, $composer);
$config = $composer->getConfig();
list($preferSource, $preferDist) = $this->getPreferredInstallOptions($config, $input);
$optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader');
$authoritative = $input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');
$install->setDryRun($input->getOption('dry-run'))->setVerbose($input->getOption('verbose'))->setPreferSource($preferSource)->setPreferDist($preferDist)->setDevMode(!$input->getOption('no-dev'))->setDumpAutoloader(!$input->getOption('no-autoloader'))->setRunScripts(!$input->getOption('no-scripts'))->setSkipSuggest($input->getOption('no-suggest'))->setOptimizeAutoloader($optimize)->setClassMapAuthoritative($authoritative)->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'));
if ($input->getOption('no-plugins')) {
$install->disablePlugins();
}
return $install->run();
}
示例7: execute
/**
* Remove packages from the root install.
*
* @param $packages array Indexed array of package names to remove
*
* @throws \Bolt\Exception\PackageManagerException
*
* @return int 0 on success or a positive error code on failure
*/
public function execute(array $packages)
{
if (empty($packages)) {
throw new PackageManagerException('No package specified for removal');
}
$io = $this->app['extend.manager']->getIO();
$options = $this->app['extend.manager']->getOptions();
$jsonFile = new JsonFile($options['composerjson']);
$composerDefinition = $jsonFile->read();
$composerBackup = file_get_contents($jsonFile->getPath());
$json = new JsonConfigSource($jsonFile);
$type = $options['dev'] ? 'require-dev' : 'require';
// Remove packages from JSON
foreach ($packages as $package) {
if (isset($composerDefinition[$type][$package])) {
$json->removeLink($type, $package);
}
}
// Reload Composer config
$composer = $this->app['extend.manager']->getFactory()->resetComposer();
$install = Installer::create($io, $composer);
try {
$install->setVerbose($options['verbose'])->setDevMode(!$options['updatenodev'])->setUpdate(true)->setUpdateWhitelist($packages)->setWhitelistDependencies($options['updatewithdependencies'])->setIgnorePlatformRequirements($options['ignoreplatformreqs']);
$status = $install->run();
if ($status !== 0) {
// Write out old JSON file
file_put_contents($jsonFile->getPath(), $composerBackup);
}
} catch (\Exception $e) {
$msg = __CLASS__ . '::' . __FUNCTION__ . ' recieved an error from Composer: ' . $e->getMessage() . ' in ' . $e->getFile() . '::' . $e->getLine();
$this->app['logger.system']->critical($msg, array('event' => 'exception', 'exception' => $e));
throw new PackageManagerException($e->getMessage(), $e->getCode(), $e);
}
return $status;
}
示例8: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$composer = $this->getComposer();
$io = $this->getApplication()->getIO();
$install = Installer::create($io, $composer);
return $install->run((bool) $input->getOption('prefer-source'), (bool) $input->getOption('dry-run'), (bool) $input->getOption('verbose'), (bool) $input->getOption('no-install-recommends'), (bool) $input->getOption('install-suggests'));
}
示例9: execute
/**
* Update packages.
*
* @param $packages array Indexed array of package names to update
* @param $options array [Optional] changed option set
*
* @throws \Bolt\Exception\PackageManagerException
*
* @return int 0 on success or a positive error code on failure
*/
public function execute(array $packages = [], array $options = [])
{
/** @var $composer \Composer\Composer */
$composer = $this->getComposer();
$io = $this->getIO();
$packageManagerOptions = $this->app['extend.action.options'];
// Handle passed in options
if (!empty($options)) {
$options = Arr::mergeRecursiveDistinct($packageManagerOptions, $options);
} else {
$options = $packageManagerOptions;
}
$install = Installer::create($io, $composer);
$config = $composer->getConfig();
$optimize = $config->get('optimize-autoloader');
// Set preferred install method
$prefer = $this->getPreferedTarget($config->get('preferred-install'));
try {
$install->setDryRun($options['dryrun'])->setVerbose($options['verbose'])->setPreferSource($prefer['source'])->setPreferDist($prefer['dist'])->setDevMode(!$options['nodev'])->setDumpAutoloader(!$options['noautoloader'])->setRunScripts(!$options['noscripts'])->setOptimizeAutoloader($optimize)->setUpdate(true)->setUpdateWhitelist($packages)->setWhitelistDependencies($options['withdependencies'])->setIgnorePlatformRequirements($options['ignoreplatformreqs'])->setPreferStable($options['preferstable'])->setPreferLowest($options['preferlowest'])->disablePlugins();
return $install->run();
} catch (\Exception $e) {
$msg = __CLASS__ . '::' . __FUNCTION__ . ' recieved an error from Composer: ' . $e->getMessage() . ' in ' . $e->getFile() . '::' . $e->getLine();
$this->app['logger.system']->critical($msg, ['event' => 'exception', 'exception' => $e]);
throw new PackageManagerException($e->getMessage(), $e->getCode(), $e);
}
}
示例10: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$composer = $this->getComposer();
$io = $this->getIO();
$install = Installer::create($io, $composer);
$install->setDryRun($input->getOption('dry-run'))->setVerbose($input->getOption('verbose'))->setPreferSource($input->getOption('prefer-source'))->setDevMode($input->getOption('dev'))->setRunScripts(!$input->getOption('no-scripts'));
return $install->run() ? 0 : 1;
}
示例11: execute
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$io = new ConsoleIO($input, $output, $this->getHelperSet());
$factory = new ComposerFactory($io);
$composer = $factory->createComposer();
$installer = Installer::create($io, $composer);
$installer->run();
}
示例12: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = $this->getIO();
if ($input->getOption('no-custom-installers')) {
$io->writeError('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
$input->setOption('no-plugins', true);
}
if ($input->getOption('dev')) {
$io->writeError('<warning>You are using the deprecated option "dev". Dev packages are installed by default now.</warning>');
}
$composer = $this->getComposer(true, $input->getOption('no-plugins'));
$packages = $input->getArgument('packages');
if ($input->getOption('interactive')) {
$packages = $this->getPackagesInteractively($io, $input, $output, $composer, $packages);
}
if ($input->getOption('root-reqs')) {
$require = array_keys($composer->getPackage()->getRequires());
if (!$input->getOption('no-dev')) {
$requireDev = array_keys($composer->getPackage()->getDevRequires());
$require = array_merge($require, $requireDev);
}
if (!empty($packages)) {
$packages = array_intersect($packages, $require);
} else {
$packages = $require;
}
}
$composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'update', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
$install = Installer::create($io, $composer);
$preferSource = false;
$preferDist = false;
$config = $composer->getConfig();
switch ($config->get('preferred-install')) {
case 'source':
$preferSource = true;
break;
case 'dist':
$preferDist = true;
break;
case 'auto':
default:
// noop
break;
}
if ($input->getOption('prefer-source') || $input->getOption('prefer-dist')) {
$preferSource = $input->getOption('prefer-source');
$preferDist = $input->getOption('prefer-dist');
}
$optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader');
$authoritative = $input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');
$install->setDryRun($input->getOption('dry-run'))->setVerbose($input->getOption('verbose'))->setPreferSource($preferSource)->setPreferDist($preferDist)->setDevMode(!$input->getOption('no-dev'))->setDumpAutoloader(!$input->getOption('no-autoloader'))->setRunScripts(!$input->getOption('no-scripts'))->setOptimizeAutoloader($optimize)->setClassMapAuthoritative($authoritative)->setUpdate(true)->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $packages)->setWhitelistDependencies($input->getOption('with-dependencies'))->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'))->setPreferStable($input->getOption('prefer-stable'))->setPreferLowest($input->getOption('prefer-lowest'));
if ($input->getOption('no-plugins')) {
$install->disablePlugins();
}
return $install->run();
}
示例13: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$packages = $input->getArgument('packages');
$file = Factory::getComposerFile();
$jsonFile = new JsonFile($file);
$composer = $jsonFile->read();
$composerBackup = file_get_contents($jsonFile->getPath());
$json = new JsonConfigSource($jsonFile);
$type = $input->getOption('dev') ? 'require-dev' : 'require';
$altType = !$input->getOption('dev') ? 'require-dev' : 'require';
$io = $this->getIO();
if ($input->getOption('update-with-dependencies')) {
$io->writeError('<warning>You are using the deprecated option "update-with-dependencies". This is now default behaviour. The --no-update-with-dependencies option can be used to remove a package without its dependencies.</warning>');
}
foreach ($packages as $package) {
if (isset($composer[$type][$package])) {
$json->removeLink($type, $package);
} elseif (isset($composer[$altType][$package])) {
$io->writeError('<warning>' . $package . ' could not be found in ' . $type . ' but it is present in ' . $altType . '</warning>');
if ($io->isInteractive()) {
if ($io->askConfirmation('Do you want to remove it from ' . $altType . ' [<comment>yes</comment>]? ', true)) {
$json->removeLink($altType, $package);
}
}
} else {
$io->writeError('<warning>' . $package . ' is not required in your composer.json and has not been removed</warning>');
}
}
if ($input->getOption('no-update')) {
return 0;
}
// Update packages
$this->resetComposer();
$composer = $this->getComposer(true, $input->getOption('no-plugins'));
$composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'remove', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
$install = Installer::create($io, $composer);
$updateDevMode = !$input->getOption('update-no-dev');
$optimize = $input->getOption('optimize-autoloader') || $composer->getConfig()->get('optimize-autoloader');
$authoritative = $input->getOption('classmap-authoritative') || $composer->getConfig()->get('classmap-authoritative');
$install->setVerbose($input->getOption('verbose'))->setDevMode($updateDevMode)->setOptimizeAutoloader($optimize)->setClassMapAuthoritative($authoritative)->setUpdate(true)->setUpdateWhitelist($packages)->setWhitelistDependencies(!$input->getOption('no-update-with-dependencies'))->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'));
$exception = null;
try {
$status = $install->run();
} catch (\Exception $exception) {
$status = 1;
}
if ($status !== 0) {
$io->writeError("\n" . '<error>Removal failed, reverting ' . $file . ' to its original content.</error>');
file_put_contents($jsonFile->getPath(), $composerBackup);
}
if ($exception) {
throw $exception;
}
return $status;
}
示例14: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$composer = $this->getComposer();
$io = $this->getIO();
$install = Installer::create($io, $composer);
$install->setDryRun($input->getOption('dry-run'))->setVerbose($input->getOption('verbose'))->setPreferSource($input->getOption('prefer-source'))->setDevMode($input->getOption('dev'))->setRunScripts(!$input->getOption('no-scripts'))->setUpdate(true)->setUpdateWhitelist($input->getArgument('packages'));
if ($input->getOption('no-custom-installers')) {
$install->disableCustomInstallers();
}
return $install->run() ? 0 : 1;
}
示例15: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$composer = $this->getComposer();
$io = $this->getIO();
$install = Installer::create($io, $composer);
$install->setDryRun($input->getOption('dry-run'))->setVerbose($input->getOption('verbose'))->setPreferSource($input->getOption('prefer-source'))->setPreferDist($input->getOption('prefer-dist'))->setDevMode($input->getOption('dev'))->setRunScripts(!$input->getOption('no-scripts'))->setOptimizeAutoloader($input->getOption('optimize-autoloader'));
if ($input->getOption('no-custom-installers')) {
$install->disableCustomInstallers();
}
return $install->run() ? 0 : 1;
}