Skip to content

Commit 7f1762f

Browse files
committed
Move fos rest, jms serializer and hateoas on dev requirements
1 parent 46a2b13 commit 7f1762f

File tree

9 files changed

+104
-20
lines changed

9 files changed

+104
-20
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ jobs:
157157
-
158158
name: Run smoke tests without friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle packages
159159
run: |
160-
composer remove friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts
160+
composer remove --dev friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts
161161
(cd tests/Application && bin/console cache:clear --env=test_without_fosrest)
162+
(cd tests/Application && bin/console lint:container --env=test_without_fosrest)
162163
composer require friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts
163164
164165
-

UPGRADE.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## UPGRADE FOR `1.12.x`
2+
3+
### FROM `1.11.x` to `1.12.x`
4+
5+
We move these following dependencies on optional requirements, so explicit them in your app requirements if you need them.
6+
7+
* friendsofsymfony/rest-bundle
8+
* jms/serializer-bundle
9+
* willdurand/hateoas-bundle
10+
111
## UPGRADE FOR `1.11.x`
212

313
### FROM `1.10.x` to `1.11.x`

composer.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@
3333
"doctrine/event-manager": "^1.1",
3434
"doctrine/inflector": "^1.4 || ^2.0",
3535
"doctrine/persistence": "^2.0 || ^3.0",
36-
"friendsofsymfony/rest-bundle": "^3.0",
3736
"gedmo/doctrine-extensions": "^2.4.12 || ^3.0",
38-
"jms/serializer-bundle": "^3.5 || ^4.0 || ^5.0",
3937
"sylius/registry": "^1.2",
4038
"symfony/config": "^5.4 || ^6.4",
4139
"symfony/deprecation-contracts": "^2.1 || ^3.0",
@@ -52,7 +50,6 @@
5250
"symfony/validator": "^5.4 || ^6.4",
5351
"symfony/yaml": "^5.4 || ^6.4",
5452
"webmozart/assert": "^1.8",
55-
"willdurand/hateoas-bundle": "^2.0",
5653
"winzou/state-machine-bundle": "^0.6",
5754
"willdurand/negotiation": "^3.1"
5855
},
@@ -61,6 +58,8 @@
6158
},
6259
"require-dev": {
6360
"doctrine/orm": "^2.5",
61+
"friendsofsymfony/rest-bundle": "^3.0",
62+
"jms/serializer-bundle": "^3.5 || ^4.0 || ^5.0",
6463
"lchrusciel/api-test-case": "^5.0",
6564
"matthiasnoback/symfony-dependency-injection-test": "^4.2.1",
6665
"pagerfanta/pagerfanta": "^3.7 || ^4.0",
@@ -84,7 +83,13 @@
8483
"rector/rector": "^0.18.2",
8584
"symfony/messenger": "^5.4 || ^6.4",
8685
"symfony/serializer": "^5.4 || ^6.4",
87-
"symfony/security-bundle": "^5.4 || ^6.4"
86+
"symfony/security-bundle": "^5.4 || ^6.4",
87+
"willdurand/hateoas-bundle": "^2.0"
88+
},
89+
"conflict": {
90+
"friendsofsymfony/rest-bundle": "<3.0",
91+
"jms/serializer-bundle": "<3.5",
92+
"willdurand/hateoas-bundle": "<2.0"
8893
},
8994
"suggest": {
9095
"doctrine/orm": "^2.5",

src/Bundle/Controller/ResourcesCollectionProvider.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@
2121

2222
final class ResourcesCollectionProvider implements ResourcesCollectionProviderInterface
2323
{
24-
private ResourcesResolverInterface $resourcesResolver;
25-
26-
private PagerfantaFactory $pagerfantaRepresentationFactory;
27-
28-
public function __construct(ResourcesResolverInterface $resourcesResolver, PagerfantaFactory $pagerfantaRepresentationFactory)
29-
{
30-
$this->resourcesResolver = $resourcesResolver;
31-
$this->pagerfantaRepresentationFactory = $pagerfantaRepresentationFactory;
24+
public function __construct(
25+
private ResourcesResolverInterface $resourcesResolver,
26+
private ?PagerfantaFactory $pagerfantaRepresentationFactory = null,
27+
) {
3228
}
3329

3430
/**
@@ -61,6 +57,10 @@ public function get(RequestConfiguration $requestConfiguration, RepositoryInterf
6157
$paginator->getCurrentPageResults();
6258

6359
if (!$requestConfiguration->isHtmlRequest()) {
60+
if (null === $this->pagerfantaRepresentationFactory) {
61+
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"');
62+
}
63+
6464
$route = new Route($request->attributes->get('_route'), array_merge($request->attributes->get('_route_params'), $request->query->all()));
6565

6666
return $this->pagerfantaRepresentationFactory->createRepresentation($paginator, $route);

src/Bundle/Controller/ViewHandler.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@
1919

2020
final class ViewHandler implements ViewHandlerInterface
2121
{
22-
private ConfigurableViewHandlerInterface $restViewHandler;
23-
24-
public function __construct(ConfigurableViewHandlerInterface $restViewHandler)
22+
public function __construct(private ConfigurableViewHandlerInterface $restViewHandler)
2523
{
26-
$this->restViewHandler = $restViewHandler;
2724
}
2825

2926
public function handle(RequestConfiguration $requestConfiguration, View $view): Response
3027
{
3128
if (!$requestConfiguration->isHtmlRequest()) {
3229
$this->restViewHandler->setExclusionStrategyGroups($requestConfiguration->getSerializationGroups() ?? []);
3330

34-
if ($version = $requestConfiguration->getSerializationVersion()) {
31+
$version = $requestConfiguration->getSerializationVersion();
32+
if (null !== $version) {
3533
$this->restViewHandler->setExclusionStrategyVersion($version);
3634
}
3735

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler;
15+
16+
use FOS\RestBundle\FOSRestBundle;
17+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18+
use Symfony\Component\DependencyInjection\ContainerBuilder;
19+
20+
final class FosRestPass implements CompilerPassInterface
21+
{
22+
public function process(ContainerBuilder $container): void
23+
{
24+
/** @var array $bundles */
25+
$bundles = $container->getParameter('kernel.bundles');
26+
27+
if (in_array(FOSRestBundle::class, $bundles, true)) {
28+
return;
29+
}
30+
31+
$container->removeDefinition('sylius.resource_controller.view_handler');
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler;
15+
16+
use Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle;
17+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18+
use Symfony\Component\DependencyInjection\ContainerBuilder;
19+
20+
final class HateoasPass implements CompilerPassInterface
21+
{
22+
public function process(ContainerBuilder $container): void
23+
{
24+
/** @var array $bundles */
25+
$bundles = $container->getParameter('kernel.bundles');
26+
27+
if (in_array(BazingaHateoasBundle::class, $bundles, true)) {
28+
return;
29+
}
30+
31+
$container->removeDefinition('sylius.resource_controller.pagerfanta_representation_factory');
32+
}
33+
}

src/Bundle/Resources/config/services/controller.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
<service id="sylius.resource_controller.resources_collection_provider" class="Sylius\Bundle\ResourceBundle\Controller\ResourcesCollectionProvider" public="false">
5252
<argument type="service" id="sylius.resource_controller.resources_resolver" />
53-
<argument type="service" id="sylius.resource_controller.pagerfanta_representation_factory" />
53+
<argument type="service" id="sylius.resource_controller.pagerfanta_representation_factory" on-invalid="null" />
5454
</service>
5555
<service id="Sylius\Bundle\ResourceBundle\Controller\ResourcesCollectionProviderInterface" alias="sylius.resource_controller.resources_collection_provider" public="false" />
5656

@@ -80,7 +80,7 @@
8080
<service id="Sylius\Bundle\ResourceBundle\Controller\EventDispatcherInterface" alias="sylius.resource_controller.event_dispatcher" public="false" />
8181

8282
<service id="sylius.resource_controller.view_handler" class="Sylius\Bundle\ResourceBundle\Controller\ViewHandler" public="false">
83-
<argument type="service" id="fos_rest.view_handler" on-invalid="null" />
83+
<argument type="service" id="fos_rest.view_handler" />
8484
</service>
8585
<service id="Sylius\Bundle\ResourceBundle\Controller\ViewHandlerInterface" alias="sylius.resource_controller.view_handler" public="false" />
8686

src/Bundle/SyliusResourceBundle.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\CsrfTokenManagerPass;
1717
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\DoctrineContainerRepositoryFactoryPass;
1818
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\DoctrineTargetEntitiesResolverPass;
19+
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\FosRestPass;
20+
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\HateoasPass;
1921
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\Helper\TargetEntitiesResolver;
2022
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\PagerfantaBridgePass;
2123
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\RegisterFormBuilderPass;
@@ -50,6 +52,8 @@ public function build(ContainerBuilder $container): void
5052
$container->addCompilerPass(new DisableMetadataCachePass());
5153
$container->addCompilerPass(new DoctrineContainerRepositoryFactoryPass());
5254
$container->addCompilerPass(new DoctrineTargetEntitiesResolverPass(new TargetEntitiesResolver()), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1);
55+
$container->addCompilerPass(new FosRestPass());
56+
$container->addCompilerPass(new HateoasPass());
5357
$container->addCompilerPass(new RegisterFormBuilderPass());
5458
$container->addCompilerPass(new RegisterFqcnControllersPass());
5559
$container->addCompilerPass(new RegisterResourceRepositoryPass());

0 commit comments

Comments
 (0)