diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index e2c94a67e..fabab144d 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -155,10 +155,11 @@ jobs:
sed -i -e 's/state_machine_component: symfony/state_machine_component: winzou/g' tests/Application/config/packages/test/sylius_resource.yaml
-
- name: Run smoke tests without friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle packages
+ name: Run lint container without friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle packages
run: |
- composer remove friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts
+ composer remove --dev friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts
(cd tests/Application && bin/console cache:clear --env=test_without_fosrest)
+ (cd tests/Application && bin/console lint:container --env=test_without_fosrest)
composer require friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts
-
diff --git a/UPGRADE.md b/UPGRADE.md
index 36106ecd4..51df9729f 100644
--- a/UPGRADE.md
+++ b/UPGRADE.md
@@ -1,3 +1,13 @@
+## UPGRADE FOR `1.12.x`
+
+### FROM `1.11.x` to `1.12.x`
+
+In preparation of removal, following dependencies were moved to optional requirements. If still in use by your app, require them explicitly in your `composer.json`.
+
+* friendsofsymfony/rest-bundle
+* jms/serializer-bundle
+* willdurand/hateoas-bundle
+
## UPGRADE FOR `1.11.x`
### FROM `1.10.x` to `1.11.x`
diff --git a/composer.json b/composer.json
index e2a28132e..636891186 100644
--- a/composer.json
+++ b/composer.json
@@ -33,9 +33,7 @@
"doctrine/event-manager": "^1.1",
"doctrine/inflector": "^1.4 || ^2.0",
"doctrine/persistence": "^2.0 || ^3.0",
- "friendsofsymfony/rest-bundle": "^3.0",
"gedmo/doctrine-extensions": "^2.4.12 || ^3.0",
- "jms/serializer-bundle": "^3.5 || ^4.0 || ^5.0",
"sylius/registry": "^1.2",
"symfony/config": "^5.4 || ^6.4",
"symfony/deprecation-contracts": "^2.1 || ^3.0",
@@ -52,7 +50,6 @@
"symfony/validator": "^5.4 || ^6.4",
"symfony/yaml": "^5.4 || ^6.4",
"webmozart/assert": "^1.8",
- "willdurand/hateoas-bundle": "^2.0",
"winzou/state-machine-bundle": "^0.6",
"willdurand/negotiation": "^3.1"
},
@@ -61,6 +58,8 @@
},
"require-dev": {
"doctrine/orm": "^2.5",
+ "friendsofsymfony/rest-bundle": "^3.0",
+ "jms/serializer-bundle": "^3.5 || ^4.0 || ^5.0",
"lchrusciel/api-test-case": "^5.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.2.1",
"pagerfanta/pagerfanta": "^3.7 || ^4.0",
@@ -84,7 +83,13 @@
"rector/rector": "^0.18.2",
"symfony/messenger": "^5.4 || ^6.4",
"symfony/serializer": "^5.4 || ^6.4",
- "symfony/security-bundle": "^5.4 || ^6.4"
+ "symfony/security-bundle": "^5.4 || ^6.4",
+ "willdurand/hateoas-bundle": "^2.0"
+ },
+ "conflict": {
+ "friendsofsymfony/rest-bundle": "<3.0",
+ "jms/serializer-bundle": "<3.5",
+ "willdurand/hateoas-bundle": "<2.0"
},
"suggest": {
"doctrine/orm": "^2.5",
diff --git a/src/Bundle/Controller/ResourcesCollectionProvider.php b/src/Bundle/Controller/ResourcesCollectionProvider.php
index eafc139de..34c159eee 100644
--- a/src/Bundle/Controller/ResourcesCollectionProvider.php
+++ b/src/Bundle/Controller/ResourcesCollectionProvider.php
@@ -21,14 +21,10 @@
final class ResourcesCollectionProvider implements ResourcesCollectionProviderInterface
{
- private ResourcesResolverInterface $resourcesResolver;
-
- private PagerfantaFactory $pagerfantaRepresentationFactory;
-
- public function __construct(ResourcesResolverInterface $resourcesResolver, PagerfantaFactory $pagerfantaRepresentationFactory)
- {
- $this->resourcesResolver = $resourcesResolver;
- $this->pagerfantaRepresentationFactory = $pagerfantaRepresentationFactory;
+ public function __construct(
+ private ResourcesResolverInterface $resourcesResolver,
+ private ?PagerfantaFactory $pagerfantaRepresentationFactory = null,
+ ) {
}
/**
@@ -61,6 +57,10 @@ public function get(RequestConfiguration $requestConfiguration, RepositoryInterf
$paginator->getCurrentPageResults();
if (!$requestConfiguration->isHtmlRequest()) {
+ if (null === $this->pagerfantaRepresentationFactory) {
+ throw new \LogicException('The "willdurand/hateoas-bundle" must be installed and configured to render a resource collection on non-HTML request. Try running "composer require willdurand/hateoas-bundle"');
+ }
+
$route = new Route($request->attributes->get('_route'), array_merge($request->attributes->get('_route_params'), $request->query->all()));
return $this->pagerfantaRepresentationFactory->createRepresentation($paginator, $route);
diff --git a/src/Bundle/Controller/ViewHandler.php b/src/Bundle/Controller/ViewHandler.php
index f0d16b757..e23fcb1d3 100644
--- a/src/Bundle/Controller/ViewHandler.php
+++ b/src/Bundle/Controller/ViewHandler.php
@@ -19,11 +19,8 @@
final class ViewHandler implements ViewHandlerInterface
{
- private ConfigurableViewHandlerInterface $restViewHandler;
-
- public function __construct(ConfigurableViewHandlerInterface $restViewHandler)
+ public function __construct(private ConfigurableViewHandlerInterface $restViewHandler)
{
- $this->restViewHandler = $restViewHandler;
}
public function handle(RequestConfiguration $requestConfiguration, View $view): Response
@@ -31,7 +28,8 @@ public function handle(RequestConfiguration $requestConfiguration, View $view):
if (!$requestConfiguration->isHtmlRequest()) {
$this->restViewHandler->setExclusionStrategyGroups($requestConfiguration->getSerializationGroups() ?? []);
- if ($version = $requestConfiguration->getSerializationVersion()) {
+ $version = $requestConfiguration->getSerializationVersion();
+ if (null !== $version) {
$this->restViewHandler->setExclusionStrategyVersion($version);
}
diff --git a/src/Bundle/DependencyInjection/Compiler/UnregisterFosRestDefinitionsPass.php b/src/Bundle/DependencyInjection/Compiler/UnregisterFosRestDefinitionsPass.php
new file mode 100644
index 000000000..3d687d5e9
--- /dev/null
+++ b/src/Bundle/DependencyInjection/Compiler/UnregisterFosRestDefinitionsPass.php
@@ -0,0 +1,33 @@
+getParameter('kernel.bundles');
+
+ if (in_array(FOSRestBundle::class, $bundles, true)) {
+ return;
+ }
+
+ $container->removeDefinition('sylius.resource_controller.view_handler');
+ }
+}
diff --git a/src/Bundle/DependencyInjection/Compiler/UnregisterHateoasDefinitionsPass.php b/src/Bundle/DependencyInjection/Compiler/UnregisterHateoasDefinitionsPass.php
new file mode 100644
index 000000000..62288351c
--- /dev/null
+++ b/src/Bundle/DependencyInjection/Compiler/UnregisterHateoasDefinitionsPass.php
@@ -0,0 +1,33 @@
+getParameter('kernel.bundles');
+
+ if (in_array(BazingaHateoasBundle::class, $bundles, true)) {
+ return;
+ }
+
+ $container->removeDefinition('sylius.resource_controller.pagerfanta_representation_factory');
+ }
+}
diff --git a/src/Bundle/Resources/config/services/controller.xml b/src/Bundle/Resources/config/services/controller.xml
index 6bf356350..ab8c86919 100644
--- a/src/Bundle/Resources/config/services/controller.xml
+++ b/src/Bundle/Resources/config/services/controller.xml
@@ -50,7 +50,7 @@
-
+
@@ -80,7 +80,7 @@
-
+
diff --git a/src/Bundle/SyliusResourceBundle.php b/src/Bundle/SyliusResourceBundle.php
index 6d992d4ae..29eca8e69 100644
--- a/src/Bundle/SyliusResourceBundle.php
+++ b/src/Bundle/SyliusResourceBundle.php
@@ -25,6 +25,8 @@
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\RegisterResourceStateMachinePass;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\RegisterStateMachinePass;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\TwigPass;
+use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\UnregisterFosRestDefinitionsPass;
+use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\UnregisterHateoasDefinitionsPass;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\WinzouStateMachinePass;
use Sylius\Bundle\ResourceBundle\DependencyInjection\PagerfantaExtension;
use Sylius\Resource\Symfony\DependencyIjection\Compiler\DisableMetadataCachePass;
@@ -56,6 +58,8 @@ public function build(ContainerBuilder $container): void
$container->addCompilerPass(new RegisterResourcesPass());
$container->addCompilerPass(new RegisterStateMachinePass());
$container->addCompilerPass(new RegisterResourceStateMachinePass());
+ $container->addCompilerPass(new UnregisterFosRestDefinitionsPass());
+ $container->addCompilerPass(new UnregisterHateoasDefinitionsPass());
$container->addCompilerPass(new TwigPass());
$container->addCompilerPass(new WinzouStateMachinePass());
diff --git a/tests/Bundle/DependencyInjection/Compiler/UnregisterFosRestDefinitionsPassTest.php b/tests/Bundle/DependencyInjection/Compiler/UnregisterFosRestDefinitionsPassTest.php
new file mode 100644
index 000000000..b8eb95224
--- /dev/null
+++ b/tests/Bundle/DependencyInjection/Compiler/UnregisterFosRestDefinitionsPassTest.php
@@ -0,0 +1,51 @@
+setParameter('kernel.bundles', []);
+
+ $this->compile();
+
+ $this->assertContainerBuilderNotHasService('sylius.resource_controller.view_handler');
+ }
+
+ /** @test */
+ public function it_keeps_the_view_handler_if_fos_rest_is_available(): void
+ {
+ $this->setParameter('kernel.bundles', [FOSRestBundle::class]);
+
+ $this->compile();
+
+ $this->assertContainerBuilderHasService('sylius.resource_controller.view_handler');
+ }
+
+ protected function registerCompilerPass(ContainerBuilder $container): void
+ {
+ $this->registerService('sylius.resource_controller.view_handler', ViewHandler::class);
+ $this->setParameter('kernel.bundles', []);
+
+ $container->addCompilerPass(new UnregisterFosRestDefinitionsPass());
+ }
+}
diff --git a/tests/Bundle/DependencyInjection/Compiler/UnregisterHateoasDefinitionsPassTest.php b/tests/Bundle/DependencyInjection/Compiler/UnregisterHateoasDefinitionsPassTest.php
new file mode 100644
index 000000000..57fa21100
--- /dev/null
+++ b/tests/Bundle/DependencyInjection/Compiler/UnregisterHateoasDefinitionsPassTest.php
@@ -0,0 +1,51 @@
+setParameter('kernel.bundles', []);
+
+ $this->compile();
+
+ $this->assertContainerBuilderNotHasService('sylius.resource_controller.pagerfanta_representation_factory');
+ }
+
+ /** @test */
+ public function it_keeps_the_view_handler_if_fos_rest_is_available(): void
+ {
+ $this->setParameter('kernel.bundles', [BazingaHateoasBundle::class]);
+
+ $this->compile();
+
+ $this->assertContainerBuilderHasService('sylius.resource_controller.pagerfanta_representation_factory');
+ }
+
+ protected function registerCompilerPass(ContainerBuilder $container): void
+ {
+ $this->registerService('sylius.resource_controller.pagerfanta_representation_factory', PagerfantaFactory::class);
+ $this->setParameter('kernel.bundles', []);
+
+ $container->addCompilerPass(new UnregisterHateoasDefinitionsPass());
+ }
+}