1
0
Fork 0

Merge remote-tracking branch 'alu/ignore-ext-require'

Conflicts:
	src/Composer/Installer.php
pull/3148/merge
Jordi Boggiano 2014-10-15 14:42:07 +01:00
commit 71976a638c
7 changed files with 85 additions and 8 deletions

View File

@ -45,6 +45,7 @@ class InstallCommand extends Command
new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'),
new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'),
new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump'),
new InputOption('ignore-platform-package-requirements', null, InputOption::VALUE_NONE, 'Ignore PHP Extention requirements.'),
new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Should not be provided, use composer require instead to add a given package to composer.json.'),
))
->setHelp(<<<EOT
@ -114,6 +115,7 @@ EOT
->setDevMode(!$input->getOption('no-dev'))
->setRunScripts(!$input->getOption('no-scripts'))
->setOptimizeAutoloader($optimize)
->setIgnorePlatformPackage($input->getOption('ignore-platform-package-requirements'));
;
if ($input->getOption('no-plugins')) {

View File

@ -45,7 +45,8 @@ class UpdateCommand extends Command
new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'),
new InputOption('with-dependencies', null, InputOption::VALUE_NONE, 'Add also all dependencies of whitelisted packages to the whitelist.'),
new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'),
new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump.')
new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump.'),
new InputOption('ignore-platform-package-requirements', null, InputOption::VALUE_NONE, 'Ignore PHP Extention requirements.'),
))
->setHelp(<<<EOT
The <info>update</info> command reads the composer.json file from the
@ -119,6 +120,7 @@ EOT
->setUpdate(true)
->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $input->getArgument('packages'))
->setWhitelistDependencies($input->getOption('with-dependencies'))
->setIgnorePlatformPackage($input->getOption('ignore-platform-package-requirements'));
;
if ($input->getOption('no-plugins')) {

View File

@ -13,6 +13,7 @@
namespace Composer\DependencyResolver;
use Composer\Repository\RepositoryInterface;
use Composer\Repository\PlatformRepository;
/**
* @author Nils Adermann <naderman@naderman.de>
@ -129,7 +130,7 @@ class Solver
}
}
protected function checkForRootRequireProblems()
protected function checkForRootRequireProblems($ignorePlatformPackageRequirements)
{
foreach ($this->jobs as $job) {
switch ($job['cmd']) {
@ -149,6 +150,10 @@ class Solver
break;
case 'install':
if ($ignorePlatformPackageRequirements && preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $job['packageName'])) {
break;
}
if (!$this->pool->whatProvides($job['packageName'], $job['constraint'])) {
$problem = new Problem($this->pool);
$problem->addRule(new Rule($this->pool, array(), null, null, $job));
@ -159,16 +164,24 @@ class Solver
}
}
public function solve(Request $request)
public function solve(Request $request, $ignorePlatformPackage = false)
{
$this->jobs = $request->getJobs();
$this->setupInstalledMap();
$this->rules = $this->ruleSetGenerator->getRulesFor($this->jobs, $this->installedMap);
$this->checkForRootRequireProblems();
$this->checkForRootRequireProblems($ignorePlatformPackage);
$this->decisions = new Decisions($this->pool);
$this->watchGraph = new RuleWatchGraph;
if ($ignorePlatformPackage) {
foreach ($this->rules as $rule) {
if ($rule->getReason() === Rule::RULE_PACKAGE_REQUIRES && preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $rule->getRequiredPackage())) {
$rule->disable();
}
}
}
foreach ($this->rules as $rule) {
$this->watchGraph->insert(new RuleWatchNode($rule));
}

View File

@ -105,6 +105,7 @@ class Installer
protected $verbose = false;
protected $update = false;
protected $runScripts = true;
protected $ignorePlatformPackage = false;
/**
* Array of package names/globs flagged for update
*
@ -263,7 +264,7 @@ class Installer
$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $policy, $pool, $installedRepo, $request);
$solver = new Solver($policy, $pool, $installedRepo);
$ops = $solver->solve($request);
$ops = $solver->solve($request, $this->ignorePlatformPackage);
$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $policy, $pool, $installedRepo, $request, $ops);
foreach ($ops as $op) {
if ($op->getJobType() === 'uninstall') {
@ -470,7 +471,7 @@ class Installer
$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $policy, $pool, $installedRepo, $request);
$solver = new Solver($policy, $pool, $installedRepo);
try {
$operations = $solver->solve($request);
$operations = $solver->solve($request, $this->ignorePlatformPackage);
$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $policy, $pool, $installedRepo, $request, $operations);
} catch (SolverProblemsException $e) {
$this->io->write('<error>Your requirements could not be resolved to an installable set of packages.</error>');
@ -1176,6 +1177,19 @@ class Installer
return $this->verbose;
}
/**
* set ignore Platform Package requirements
*
* @param boolean $ignorePlatformPackage
* @return Installer
*/
public function setIgnorePlatformPackage($ignorePlatformPackage = false)
{
$this->ignorePlatformPackage = (boolean) $ignorePlatformPackage;
return $this;
}
/**
* restrict the update operation to a few packages, all other packages
* that are already installed will be kept at their current version

View File

@ -0,0 +1,20 @@
--TEST--
Install in ignore-platform-package-requirements mode
--COMPOSER--
{
"repositories": [
{
"type": "package",
"package": [
{ "name": "a/a", "version": "1.0.0", "require": { "ext-testdummy": "*" } }
]
}
],
"require": {
"a/a": "1.0.0"
}
}
--RUN--
install --ignore-platform-package-requirements
--EXPECT--
Installing a/a (1.0.0)

View File

@ -0,0 +1,24 @@
--TEST--
Update in ignore-platform-package-requirements mode
--COMPOSER--
{
"repositories": [
{
"type": "package",
"package": [
{ "name": "a/a", "version": "1.0.1", "require": { "ext-testdummy": "*" } }
]
}
],
"require": {
"a/a": "1.0.*"
}
}
--INSTALLED--
[
{ "name": "a/a", "version": "1.0.0" }
]
--RUN--
update --ignore-platform-package-requirements
--EXPECT--
Updating a/a (1.0.0) to a/a (1.0.1)

View File

@ -204,7 +204,8 @@ class InstallerTest extends TestCase
$application->get('install')->setCode(function ($input, $output) use ($installer) {
$installer
->setDevMode(!$input->getOption('no-dev'))
->setDryRun($input->getOption('dry-run'));
->setDryRun($input->getOption('dry-run'))
->setIgnorePlatformPackage($input->getOption('ignore-platform-package-requirements'));
return $installer->run();
});
@ -215,7 +216,8 @@ class InstallerTest extends TestCase
->setUpdate(true)
->setDryRun($input->getOption('dry-run'))
->setUpdateWhitelist($input->getArgument('packages'))
->setWhitelistDependencies($input->getOption('with-dependencies'));
->setWhitelistDependencies($input->getOption('with-dependencies'))
->setIgnorePlatformPackage($input->getOption('ignore-platform-package-requirements'));
return $installer->run();
});