diff --git a/composer.json b/composer.json index 553ed57cbc..390a2c8dc2 100644 --- a/composer.json +++ b/composer.json @@ -92,7 +92,7 @@ "api-platform/http-cache": "self.version", "api-platform/hydra": "self.version", "api-platform/json-api": "self.version", - "api-platform/json-hal": "self.version", + "api-platform/hal": "self.version", "api-platform/json-schema": "self.version", "api-platform/jsonld": "self.version", "api-platform/laravel": "self.version", @@ -146,7 +146,7 @@ "illuminate/routing": "^11.0 || ^12.0", "illuminate/support": "^11.0 || ^12.0", "jangregor/phpstan-prophecy": "^2.1.11", - "justinrainbow/json-schema": "^5.2.11", + "justinrainbow/json-schema": "5.3.0", "laravel/framework": "^11.0 || ^12.0", "orchestra/testbench": "^9.1", "phpspec/prophecy-phpunit": "^2.2", diff --git a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php index de46a0aa66..405af850fc 100644 --- a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php +++ b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php @@ -47,6 +47,7 @@ use ApiPlatform\Symfony\Validator\Metadata\Property\Restriction\PropertySchemaRestrictionMetadataInterface; use ApiPlatform\Symfony\Validator\ValidationGroupsGeneratorInterface; use ApiPlatform\Validator\Exception\ValidationException; +use Composer\InstalledVersions; use Doctrine\Persistence\ManagerRegistry; use PHPStan\PhpDocParser\Parser\PhpDocParser; use Ramsey\Uuid\Uuid; @@ -635,6 +636,10 @@ private function registerJsonApiConfiguration(array $formats, PhpFileLoader $loa return; } + if (!InstalledVersions::isInstalled('api-platform/json-api')) { + throw new \LogicException('JSON-API support cannot be enabled as the JSON-API component is not installed. Try running "composer require api-platform/json-api".'); + } + $loader->load('jsonapi.php'); $loader->load('state/jsonapi.php'); } @@ -666,6 +671,10 @@ private function registerJsonHalConfiguration(array $formats, PhpFileLoader $loa return; } + if (!InstalledVersions::isInstalled('api-platform/hal')) { + throw new \LogicException('HAL support cannot be enabled as the HAL component is not installed. Try running "composer require api-platform/hal".'); + } + $loader->load('hal.php'); } @@ -738,6 +747,10 @@ private function registerDoctrineOrmConfiguration(ContainerBuilder $container, a return; } + if (!InstalledVersions::isInstalled('api-platform/doctrine-orm')) { + throw new \LogicException('Doctrine support cannot be enabled as the doctrine ORM component is not installed. Try running "composer require api-platform/doctrine-orm".'); + } + // For older versions of doctrine bridge this allows autoconfiguration for filters if (!$container->has(ManagerRegistry::class)) { $container->setAlias(ManagerRegistry::class, 'doctrine'); @@ -770,6 +783,10 @@ private function registerDoctrineMongoDbOdmConfiguration(ContainerBuilder $conta return; } + if (!InstalledVersions::isInstalled('api-platform/doctrine-odm')) { + throw new \LogicException('Doctrine MongoDB ODM support cannot be enabled as the doctrine ODM component is not installed. Try running "composer require api-platform/doctrine-odm".'); + } + $container->registerForAutoconfiguration(AggregationItemExtensionInterface::class) ->addTag('api_platform.doctrine_mongodb.odm.aggregation_extension.item'); $container->registerForAutoconfiguration(AggregationCollectionExtensionInterface::class) @@ -879,6 +896,10 @@ private function registerMercureConfiguration(ContainerBuilder $container, array return; } + if (!InstalledVersions::isInstalled('symfony/mercure-bundle')) { + throw new \LogicException('Mercure support cannot be enabled as the Symfony Mercure Bundle is not installed. Try running "composer require symfony/mercure-bundle".'); + } + $container->setParameter('api_platform.mercure.include_type', $config['mercure']['include_type']); $loader->load('state/mercure.php'); @@ -900,6 +921,10 @@ private function registerMessengerConfiguration(ContainerBuilder $container, arr return; } + if (!InstalledVersions::isInstalled('symfony/messenger')) { + throw new \LogicException('Messenger support cannot be enabled as the Symfony Messenger component is not installed. Try running "composer require symfony/messenger".'); + } + $loader->load('messenger.php'); } @@ -913,6 +938,10 @@ private function registerElasticsearchConfiguration(ContainerBuilder $container, return; } + if (!InstalledVersions::isInstalled('api-platform/elasticsearch')) { + throw new \LogicException('Elasticsearch support cannot be enabled as the Elasticsearch component is not installed. Try running "composer require api-platform/elasticsearch".'); + } + $clientClass = !class_exists(\Elasticsearch\Client::class) // ES v7 ? \Elastic\Elasticsearch\Client::class diff --git a/src/Symfony/composer.json b/src/Symfony/composer.json index eb5fe65426..ecacfbe38c 100644 --- a/src/Symfony/composer.json +++ b/src/Symfony/composer.json @@ -53,6 +53,7 @@ "api-platform/doctrine-orm": "^4.2.3", "api-platform/elasticsearch": "^4.2.3", "api-platform/graphql": "^4.2.3", + "api-platform/hal": "^4.2.3", "phpspec/prophecy-phpunit": "^2.2", "phpunit/phpunit": "11.5.x-dev", "symfony/expression-language": "^6.4 || ^7.0 || ^8.0", @@ -70,6 +71,7 @@ "api-platform/elasticsearch": "To support Elasticsearch.", "api-platform/graphql": "To support GraphQL.", "api-platform/hal": "to support the HAL format", + "api-platform/json-api": "to support the JSON-API format", "api-platform/ramsey-uuid": "To support Ramsey's UUID identifiers.", "phpstan/phpdoc-parser": "To support extracting metadata from PHPDoc.", "psr/cache-implementation": "To use metadata caching.",