diff --git a/src/RequirementChecker/AppRequirementsFactory.php b/src/RequirementChecker/AppRequirementsFactory.php index db83165f2..74a02a516 100644 --- a/src/RequirementChecker/AppRequirementsFactory.php +++ b/src/RequirementChecker/AppRequirementsFactory.php @@ -28,11 +28,39 @@ final class AppRequirementsFactory { private const SELF_PACKAGE = null; + public function createUnfiltered( + ComposerJson $composerJson, + ComposerLock $composerLock, + CompressionAlgorithm $compressionAlgorithm, + ): Requirements { + return $this + ->createBuilder( + $composerJson, + $composerLock, + $compressionAlgorithm, + ) + ->getAll(); + } + public function create( ComposerJson $composerJson, ComposerLock $composerLock, CompressionAlgorithm $compressionAlgorithm, ): Requirements { + return $this + ->createBuilder( + $composerJson, + $composerLock, + $compressionAlgorithm, + ) + ->build(); + } + + private function createBuilder( + ComposerJson $composerJson, + ComposerLock $composerLock, + CompressionAlgorithm $compressionAlgorithm, + ): RequirementsBuilder { $requirementsBuilder = new RequirementsBuilder(); self::retrievePhpVersionRequirements($requirementsBuilder, $composerJson, $composerLock); @@ -40,7 +68,7 @@ public function create( self::collectComposerLockExtensionRequirements($composerLock, $requirementsBuilder); self::collectComposerJsonExtensionRequirements($composerJson, $requirementsBuilder); - return $requirementsBuilder->build(); + return $requirementsBuilder; } private static function retrievePhpVersionRequirements( diff --git a/src/RequirementChecker/Requirement.php b/src/RequirementChecker/Requirement.php index fe1d8e3ef..6c198c4bb 100644 --- a/src/RequirementChecker/Requirement.php +++ b/src/RequirementChecker/Requirement.php @@ -86,6 +86,26 @@ public static function forRequiredExtension(string $extension, ?string $packageN ); } + public static function forProvidedExtension(string $extension, ?string $packageName): self + { + return new self( + RequirementType::PROVIDED_EXTENSION, + $extension, + $packageName, + null === $packageName + ? sprintf( + 'This application provides the extension "%s".', + $extension, + ) + : sprintf( + 'The package "%s" provides the extension "%s".', + $packageName, + $extension, + ), + '', + ); + } + public static function forConflictingExtension(string $extension, ?string $packageName): self { return new self( diff --git a/src/RequirementChecker/RequirementType.php b/src/RequirementChecker/RequirementType.php index e5edb1882..89d5e642a 100644 --- a/src/RequirementChecker/RequirementType.php +++ b/src/RequirementChecker/RequirementType.php @@ -18,5 +18,6 @@ enum RequirementType: string { case PHP = 'php'; case EXTENSION = 'extension'; + case PROVIDED_EXTENSION = 'provided-extension'; case EXTENSION_CONFLICT = 'extension-conflict'; } diff --git a/src/RequirementChecker/RequirementsBuilder.php b/src/RequirementChecker/RequirementsBuilder.php index 0ce061248..f13bebeba 100644 --- a/src/RequirementChecker/RequirementsBuilder.php +++ b/src/RequirementChecker/RequirementsBuilder.php @@ -49,6 +49,40 @@ public function addConflictingExtension(Extension $extension, ?string $source): $this->conflictingExtensions[$extension->name][] = $source; } + public function getAll(): Requirements + { + $requirements = $this->predefinedRequirements; + + foreach ($this->getUnfilteredSortedRequiredExtensions() as $extensionName => $sources) { + foreach ($sources as $source) { + $requirements[] = Requirement::forRequiredExtension( + $extensionName, + $source, + ); + } + } + + foreach ($this->getSortedProvidedExtensions() as $extensionName => $sources) { + foreach ($sources as $source) { + $requirements[] = Requirement::forProvidedExtension( + $extensionName, + $source, + ); + } + } + + foreach ($this->getSortedConflictedExtensions() as $extensionName => $sources) { + foreach ($sources as $source) { + $requirements[] = Requirement::forConflictingExtension( + $extensionName, + $source, + ); + } + } + + return new Requirements($requirements); + } + public function build(): Requirements { $requirements = $this->predefinedRequirements; @@ -74,6 +108,31 @@ public function build(): Requirements return new Requirements($requirements); } + /** + * @return array> + */ + private function getUnfilteredSortedRequiredExtensions(): array + { + return array_map( + self::createSortedDistinctList(...), + self::sortByExtensionName( + $this->requiredExtensions, + ), + ); + } + /** + * @return array> + */ + private function getSortedProvidedExtensions(): array + { + return array_map( + self::createSortedDistinctList(...), + self::sortByExtensionName( + $this->providedExtensions, + ), + ); + } + /** * @return array> */