1818use Composer \Package \Link ;
1919use Composer \Package \LinkConstraint \LinkConstraintInterface ;
2020use Composer \Package \LinkConstraint \VersionConstraint ;
21+ use Composer \Package \LinkConstraint \EmptyConstraint ;
2122use Composer \Repository \RepositoryInterface ;
2223use Composer \Repository \CompositeRepository ;
2324use Composer \Repository \ComposerRepository ;
@@ -38,6 +39,7 @@ class Pool
3839 const MATCH = 1 ;
3940 const MATCH_PROVIDE = 2 ;
4041 const MATCH_REPLACE = 3 ;
42+ const MATCH_FILTERED = 4 ;
4143
4244 protected $ repositories = array ();
4345 protected $ providerRepos = array ();
@@ -47,9 +49,10 @@ class Pool
4749 protected $ stabilityFlags ;
4850 protected $ versionParser ;
4951 protected $ providerCache = array ();
52+ protected $ filterRequires ;
5053 protected $ id = 1 ;
5154
52- public function __construct ($ minimumStability = 'stable ' , array $ stabilityFlags = array ())
55+ public function __construct ($ minimumStability = 'stable ' , array $ stabilityFlags = array (), array $ filterRequires = array () )
5356 {
5457 $ stabilities = BasePackage::$ stabilities ;
5558 $ this ->versionParser = new VersionParser ;
@@ -60,6 +63,7 @@ public function __construct($minimumStability = 'stable', array $stabilityFlags
6063 }
6164 }
6265 $ this ->stabilityFlags = $ stabilityFlags ;
66+ $ this ->filterRequires = $ filterRequires ;
6367 }
6468
6569 /**
@@ -109,6 +113,7 @@ public function addRepository(RepositoryInterface $repo, $rootAliases = array())
109113
110114 if ($ exempt || $ this ->isPackageAcceptable ($ names , $ stability )) {
111115 $ package ['id ' ] = $ this ->id ++;
116+ $ package ['stability ' ] = $ stability ;
112117 $ this ->packages [] = $ package ;
113118
114119 foreach ($ names as $ provided ) {
@@ -275,6 +280,9 @@ private function computeWhatProvides($name, $constraint)
275280 $ matches [] = $ this ->ensurePackageIsLoaded ($ candidate );
276281 break ;
277282
283+ case self ::MATCH_FILTERED :
284+ break ;
285+
278286 default :
279287 throw new \UnexpectedValueException ('Unexpected match type ' );
280288 }
@@ -367,18 +375,30 @@ private function match($candidate, $name, LinkConstraintInterface $constraint =
367375 if (is_array ($ candidate )) {
368376 $ candidateName = $ candidate ['name ' ];
369377 $ candidateVersion = $ candidate ['version ' ];
378+ $ isDev = $ candidate ['stability ' ] === 'dev ' ;
379+ $ isAlias = isset ($ candidate ['alias_of ' ]);
370380 } else {
371381 // handle object packages
372382 $ candidateName = $ candidate ->getName ();
373383 $ candidateVersion = $ candidate ->getVersion ();
384+ $ isDev = $ candidate ->getStability () === 'dev ' ;
385+ $ isAlias = $ candidate instanceof AliasPackage;
386+ }
387+
388+ if (!$ isDev && !$ isAlias && isset ($ this ->filterRequires [$ name ])) {
389+ $ requireFilter = $ this ->filterRequires [$ name ];
390+ } else {
391+ $ requireFilter = new EmptyConstraint ;
374392 }
375393
376394 if ($ candidateName === $ name ) {
377- if ($ constraint === null ) {
378- return self ::MATCH ;
395+ $ pkgConstraint = new VersionConstraint ('== ' , $ candidateVersion );
396+
397+ if ($ constraint === null || $ constraint ->matches ($ pkgConstraint )) {
398+ return $ requireFilter ->matches ($ pkgConstraint ) ? self ::MATCH : self ::MATCH_FILTERED ;
379399 }
380400
381- return $ constraint -> matches ( new VersionConstraint ( ' == ' , $ candidateVersion )) ? self :: MATCH : self ::MATCH_NAME ;
401+ return self ::MATCH_NAME ;
382402 }
383403
384404 if (is_array ($ candidate )) {
@@ -393,29 +413,29 @@ private function match($candidate, $name, LinkConstraintInterface $constraint =
393413 $ replaces = $ candidate ->getReplaces ();
394414 }
395415
396- // aliases create multiple replaces/provides for one target so they can not use the shortcut
416+ // aliases create multiple replaces/provides for one target so they can not use the shortcut below
397417 if (isset ($ replaces [0 ]) || isset ($ provides [0 ])) {
398418 foreach ($ provides as $ link ) {
399419 if ($ link ->getTarget () === $ name && ($ constraint === null || $ constraint ->matches ($ link ->getConstraint ()))) {
400- return self ::MATCH_PROVIDE ;
420+ return $ requireFilter -> matches ( $ link -> getConstraint ()) ? self ::MATCH_PROVIDE : self :: MATCH_FILTERED ;
401421 }
402422 }
403423
404424 foreach ($ replaces as $ link ) {
405425 if ($ link ->getTarget () === $ name && ($ constraint === null || $ constraint ->matches ($ link ->getConstraint ()))) {
406- return self ::MATCH_REPLACE ;
426+ return $ requireFilter -> matches ( $ link -> getConstraint ()) ? self ::MATCH_REPLACE : self :: MATCH_FILTERED ;
407427 }
408428 }
409429
410430 return self ::MATCH_NONE ;
411431 }
412432
413433 if (isset ($ provides [$ name ]) && ($ constraint === null || $ constraint ->matches ($ provides [$ name ]->getConstraint ()))) {
414- return self ::MATCH_PROVIDE ;
434+ return $ requireFilter -> matches ( $ provides [ $ name ]-> getConstraint ()) ? self ::MATCH_PROVIDE : self :: MATCH_FILTERED ;
415435 }
416436
417437 if (isset ($ replaces [$ name ]) && ($ constraint === null || $ constraint ->matches ($ replaces [$ name ]->getConstraint ()))) {
418- return self ::MATCH_REPLACE ;
438+ return $ requireFilter -> matches ( $ replaces [ $ name ]-> getConstraint ()) ? self ::MATCH_REPLACE : self :: MATCH_FILTERED ;
419439 }
420440
421441 return self ::MATCH_NONE ;
0 commit comments