@@ -102,6 +102,11 @@ class ExtrasCommand extends Command
102102 */
103103 protected $ catalogError = '' ;
104104
105+ /**
106+ * @var array|null
107+ */
108+ protected $ extrasCatalogPackages = null ;
109+
105110 /**
106111 * PackageCommand constructor.
107112 */
@@ -678,27 +683,46 @@ protected function getDependencyProviders($packageName)
678683 }
679684
680685 $ providers = [];
681- foreach (array_keys ($ requires ) as $ dependency ) {
686+ $ visited = [$ packageName => true ];
687+ $ queue = array_keys ($ requires );
688+ $ catalogPackages = $ this ->getExtrasCatalogPackages ();
689+ $ useCatalog = $ catalogPackages !== [];
690+ while ($ queue !== []) {
691+ $ dependency = array_pop ($ queue );
682692 if (!is_string ($ dependency )) {
683693 continue ;
684694 }
685695 $ dependency = trim ($ dependency );
686696 if (!$ this ->isComposerDependencyName ($ dependency )) {
687697 continue ;
688698 }
689- if ($ dependency === $ packageName ) {
699+ if (isset ( $ visited [ $ dependency ]) ) {
690700 continue ;
691701 }
702+ $ visited [$ dependency ] = true ;
692703
693704 $ depComposer = $ this ->getPackageComposer ($ dependency );
694705 if (!$ depComposer ) {
695706 continue ;
696707 }
697- if (!$ this ->isEvoPackageType ($ depComposer ['type ' ] ?? null )) {
708+ if ($ useCatalog ) {
709+ if (!isset ($ catalogPackages [strtolower ($ dependency )])) {
710+ continue ;
711+ }
712+ } elseif (!$ this ->isEvoPackageType ($ depComposer ['type ' ] ?? null )) {
698713 continue ;
699714 }
700715
701716 $ providers = array_merge ($ providers , $ this ->extractProviders ($ depComposer ));
717+
718+ $ depRequires = $ depComposer ['require ' ] ?? [];
719+ if (is_array ($ depRequires ) && $ depRequires !== []) {
720+ foreach (array_keys ($ depRequires ) as $ childDependency ) {
721+ if (is_string ($ childDependency )) {
722+ $ queue [] = $ childDependency ;
723+ }
724+ }
725+ }
702726 }
703727
704728 $ providers = array_filter ($ providers , 'is_string ' );
@@ -747,6 +771,47 @@ protected function isComposerDependencyName(string $name): bool
747771 return true ;
748772 }
749773
774+ protected function isExtrasCatalogPackage (string $ packageName ): bool
775+ {
776+ if ($ packageName === '' ) {
777+ return false ;
778+ }
779+ $ packages = $ this ->getExtrasCatalogPackages ();
780+ return isset ($ packages [strtolower ($ packageName )]);
781+ }
782+
783+ protected function getExtrasCatalogPackages (): array
784+ {
785+ if ($ this ->extrasCatalogPackages !== null ) {
786+ return $ this ->extrasCatalogPackages ;
787+ }
788+
789+ $ catalog = $ this ->loadExtrasCatalog ();
790+ if ($ catalog === null ) {
791+ $ this ->extrasCatalogPackages = [];
792+ return $ this ->extrasCatalogPackages ;
793+ }
794+
795+ $ packages = [];
796+ foreach ($ catalog ['packages ' ] ?? [] as $ pkg ) {
797+ if (!is_array ($ pkg )) {
798+ continue ;
799+ }
800+ $ composerName = $ pkg ['composer_name ' ] ?? '' ;
801+ if (is_string ($ composerName ) && $ composerName !== '' ) {
802+ $ packages [strtolower ($ composerName )] = true ;
803+ continue ;
804+ }
805+ $ fullName = $ pkg ['full_name ' ] ?? '' ;
806+ if (is_string ($ fullName ) && $ fullName !== '' ) {
807+ $ packages [strtolower ($ fullName )] = true ;
808+ }
809+ }
810+
811+ $ this ->extrasCatalogPackages = $ packages ;
812+ return $ this ->extrasCatalogPackages ;
813+ }
814+
750815 protected function getPackageComposerPath ($ packageName )
751816 {
752817 if (class_exists ('\\Composer \\InstalledVersions ' )) {
0 commit comments