Skip to content

Commit 2a908ba

Browse files
authored
feature #863 Adding support for Symfony 7 (loic425)
This PR was merged into the 1.12 branch. Discussion ---------- | Q | A | --------------- | ----- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | | License | MIT This PR replaces #840 Commits ------- 85f4576 Move fos rest, jms serializer and hateoas on dev requirements 2b7ff42 Add tests for compiler passes da7871f Rename compiler passes 4dfc684 Allow SF7 on dependencies d29e5fe SF7 Fix the sf7 build 6ac896f Bump symfony-dependency-injection-test 9ec1840 [SF7] Bump grid version 9f47ea9 [SF7] Bump Doctrine event manager version c7c6a49 [SF7] Add removed symfony container aware trait 5a524b3 [SF7] Remove enable authenticator manager option on test application a81388b Upgrade winzou on dev branch 3c3d761 [SF7] Remove hateoas on Symfony 7 7d8b62e [SF7] Fix resource loader cffcc4a Use abstract loader from Symfony 34bfd2f Fix analysis errors 8beb5e5 Fix PHPStan errors fd5ca0e Add suggestion from code review 6de5b05 [SF7] Fix phpspec tests 66338cf [SF7] Fix PHPUnit tests 15d8cc4 [SF7] Bump Winzou state machine version dc9daca Fix target entities resolving with Symfony 7 d12b302 Fix Psalm error 5b8a233 Fix coding standard c3ff04d Small fix d622fa2 Remove experimental on CI build & bump php version on component ae24d74 Fix coding standard and add conflict explanation d15296e Test CI 7371171 Fix ORM translatable listener to support SF7
2 parents 851babc + 7371171 commit 2a908ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+478
-215
lines changed

.github/workflows/build.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
tests:
1515
runs-on: ubuntu-latest
1616
name: "PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, Twig ${{ matrix.twig }}, Persistence: ${{ matrix.persistence }}, Collections: ${{ matrix.collections }}"
17+
env:
18+
APP_ENV: ${{ matrix.app_env }}
1719
strategy:
1820
fail-fast: false
1921
matrix:
@@ -22,10 +24,15 @@ jobs:
2224
symfony: ["^5.4", "^6.4"]
2325
persistence: ["^2.0", "^3.0"]
2426
collections: ["^1.8", "^2.0"]
27+
app_env: ["test"]
2528
include:
2629
- php: "8.1"
2730
pagerfanta: "^3.7"
2831
symfony: "^5.4"
32+
app_env: "test"
33+
- php: "8.3"
34+
symfony: "^7.0"
35+
app_env: "test_without_hateoas"
2936
exclude:
3037
- php: "8.1"
3138
collections: "^2.0"
@@ -82,6 +89,11 @@ jobs:
8289
if: matrix.collections != ''
8390
run: composer require "doctrine/collections:${{ matrix.collections }}" --no-update --no-scripts
8491

92+
-
93+
name: Remove hateoas on Symfony 7
94+
if: matrix.symfony == '^7.0'
95+
run: composer remove --dev willdurand/hateoas-bundle --no-update --no-scripts
96+
8597
-
8698
name: Install dependencies
8799
run: |
@@ -124,7 +136,7 @@ jobs:
124136
if: ${{ true != contains( matrix.php, '8.2' ) }}
125137
run: |
126138
sed -i -e 's/state_machine_component: symfony/state_machine_component: winzou/g' tests/Application/config/packages/test/sylius_resource.yaml
127-
(cd tests/Application && bin/console cache:clear --env=test)
139+
(cd tests/Application && bin/console cache:clear)
128140
vendor/bin/phpspec run --ansi --no-interaction
129141
sed -i -e 's/state_machine_component: winzou/state_machine_component: symfony/g' tests/Application/config/packages/test/sylius_resource.yaml
130142
@@ -133,7 +145,7 @@ jobs:
133145
name: Run state machine PHPUnit tests with winzou/state-machine package
134146
run: |
135147
sed -i -e 's/state_machine_component: symfony/state_machine_component: winzou/g' tests/Application/config/packages/test/sylius_resource.yaml
136-
(cd tests/Application && bin/console cache:clear --env=test)
148+
(cd tests/Application && bin/console cache:clear)
137149
vendor/bin/phpunit --colors=always
138150
sed -i -e 's/state_machine_component: winzou/state_machine_component: symfony/g' tests/Application/config/packages/test/sylius_resource.yaml
139151
@@ -142,28 +154,30 @@ jobs:
142154
if: ${{ true != contains( matrix.php, '8.2' ) }}
143155
run: |
144156
sed -i -e 's/state_machine_component: winzou/state_machine_component: symfony/g' tests/Application/config/packages/test/sylius_resource.yaml
145-
(cd tests/Application && bin/console cache:clear --env=test)
157+
(cd tests/Application && bin/console cache:clear)
146158
vendor/bin/phpspec run --ansi --no-interaction
147159
sed -i -e 's/state_machine_component: symfony/state_machine_component: winzou/g' tests/Application/config/packages/test/sylius_resource.yaml
148160
149161
-
150162
name: Run state machine PHPUnit tests with symfony/workflow package
151163
run: |
152164
sed -i -e 's/state_machine_component: winzou/state_machine_component: symfony/g' tests/Application/config/packages/test/sylius_resource.yaml
153-
(cd tests/Application && bin/console cache:clear --env=test)
165+
(cd tests/Application && bin/console cache:clear)
154166
vendor/bin/phpunit --colors=always
155167
sed -i -e 's/state_machine_component: symfony/state_machine_component: winzou/g' tests/Application/config/packages/test/sylius_resource.yaml
156168
157169
-
158170
name: Run lint container without friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle packages
171+
if: matrix.app_env == 'test'
159172
run: |
160173
composer remove --dev friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts
161174
(cd tests/Application && bin/console cache:clear --env=test_without_fosrest)
162175
(cd tests/Application && bin/console lint:container --env=test_without_fosrest)
163-
composer require friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts
176+
composer require --dev friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts
164177
165178
-
166179
name: Run lint container without winzou/state-machine-bundle package
180+
if: matrix.app_env == 'test'
167181
run: |
168182
composer remove winzou/state-machine-bundle --no-scripts
169183
(cd tests/Application && bin/console cache:clear --env=test_without_state_machine)
@@ -172,6 +186,7 @@ jobs:
172186
173187
-
174188
name: Run lint container without twig/twig package
189+
if: matrix.app_env == 'test'
175190
run: |
176191
composer remove symfony/twig-bundle --no-scripts
177192
composer remove sylius/grid-bundle --no-scripts --dev

CONFLICTS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22

33
This document explains why certain conflicts were added to `composer.json` and
44
references related issues.
5+
6+
- `willdurand/hateoas-bundle: ^2.6`
7+
8+
This version allows Symfony 7 but does not support the "annotation_reader" service removal.
9+
@see https://github.com/willdurand/BazingaHateoasBundle/issues/108

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ COPY . /app
1515

1616
WORKDIR /app
1717

18+
RUN composer global config --no-plugins allow-plugins.symfony/flex true
19+
RUN composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.10"
1820
RUN composer update --with-all-dependencies --no-interaction --no-progress
1921

2022
WORKDIR /app/tests/Application

composer.json

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,27 @@
3030
"doctrine/annotations": "^2.0",
3131
"doctrine/collections": "^1.8 || ^2.0",
3232
"doctrine/doctrine-bundle": "^2.0",
33-
"doctrine/event-manager": "^1.1",
33+
"doctrine/event-manager": "^1.1 || ^2.0",
3434
"doctrine/inflector": "^1.4 || ^2.0",
3535
"doctrine/persistence": "^2.0 || ^3.0",
3636
"gedmo/doctrine-extensions": "^2.4.12 || ^3.0",
3737
"sylius/registry": "^1.2",
38-
"symfony/config": "^5.4 || ^6.4",
38+
"symfony/config": "^5.4 || ^6.4 || ^7.0",
3939
"symfony/deprecation-contracts": "^2.1 || ^3.0",
40-
"symfony/expression-language": "^5.4 || ^6.4",
41-
"symfony/form": "^5.4 || ^6.4",
42-
"symfony/framework-bundle": "^5.4 || ^6.4",
43-
"symfony/http-foundation": "^5.4 || ^6.4",
44-
"symfony/intl": "^5.4 || ^6.4",
45-
"symfony/security-core": "^5.4 || ^6.4",
46-
"symfony/security-csrf": "^5.4 || ^6.4",
47-
"symfony/routing": "^5.4 || ^6.4",
48-
"symfony/translation": "^5.4 || ^6.4",
49-
"symfony/twig-bundle": "^5.4 || ^6.4",
50-
"symfony/validator": "^5.4 || ^6.4",
51-
"symfony/yaml": "^5.4 || ^6.4",
40+
"symfony/expression-language": "^5.4 || ^6.4 || ^7.0",
41+
"symfony/form": "^5.4 || ^6.4 || ^7.0",
42+
"symfony/framework-bundle": "^5.4 || ^6.4 || ^7.0",
43+
"symfony/http-foundation": "^5.4 || ^6.4 || ^7.0",
44+
"symfony/intl": "^5.4 || ^6.4 || ^7.0",
45+
"symfony/security-core": "^5.4 || ^6.4 || ^7.0",
46+
"symfony/security-csrf": "^5.4 || ^6.4 || ^7.0",
47+
"symfony/routing": "^5.4 || ^6.4 || ^7.0",
48+
"symfony/translation": "^5.4 || ^6.4 || ^7.0",
49+
"symfony/twig-bundle": "^5.4 || ^6.4 || ^7.0",
50+
"symfony/validator": "^5.4 || ^6.4 || ^7.0",
51+
"symfony/yaml": "^5.4 || ^6.4 || ^7.0",
5252
"webmozart/assert": "^1.8",
53-
"winzou/state-machine-bundle": "^0.6",
53+
"winzou/state-machine-bundle": "^0.6.2",
5454
"willdurand/negotiation": "^3.1"
5555
},
5656
"replace": {
@@ -61,7 +61,7 @@
6161
"friendsofsymfony/rest-bundle": "^3.0",
6262
"jms/serializer-bundle": "^3.5 || ^4.0 || ^5.0",
6363
"lchrusciel/api-test-case": "^5.0",
64-
"matthiasnoback/symfony-dependency-injection-test": "^4.2.1",
64+
"matthiasnoback/symfony-dependency-injection-test": "^4.2.1 || ^5.1",
6565
"pagerfanta/pagerfanta": "^3.7 || ^4.0",
6666
"pamil/phpspec-skip-example-extension": "^4.2",
6767
"phpspec/phpspec": "^7.3",
@@ -70,26 +70,27 @@
7070
"phpstan/phpstan-phpunit": "^1.1",
7171
"phpstan/phpstan-webmozart-assert": "^1.2",
7272
"phpunit/phpunit": "^9.5",
73+
"rector/rector": "^0.18.2",
7374
"sylius-labs/coding-standard": "^4.0",
74-
"sylius/grid-bundle": "^1.7 || v1.12.0-ALPHA.1",
75-
"symfony/console": "^5.4 || ^6.4",
76-
"symfony/dependency-injection": "^5.4 || ^6.4",
77-
"symfony/dotenv": "^5.4 || ^6.4",
78-
"symfony/stopwatch": "^5.4 || ^6.4",
79-
"symfony/uid": "^5.4 || ^6.4",
80-
"symfony/workflow": "^5.4 || ^6.4",
75+
"sylius/grid-bundle": "^1.7 || dev-symfony-7",
76+
"symfony/console": "^5.4 || ^6.4 || ^7.0",
77+
"symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0",
78+
"symfony/dotenv": "^5.4 || ^6.4 || ^7.0",
79+
"symfony/http-kernel": "^5.4 || ^6.4 || ^7.0",
80+
"symfony/stopwatch": "^5.4 || ^6.4 || ^7.0",
81+
"symfony/uid": "^5.4 || ^6.4 || ^7.0",
82+
"symfony/workflow": "^5.4 || ^6.4 || ^7.0",
83+
"symfony/messenger": "^5.4 || ^6.4 || ^7.0",
84+
"symfony/serializer": "^5.4 || ^6.4 || ^7.0",
85+
"symfony/security-bundle": "^5.4 || ^6.4 || ^7.0",
8186
"twig/twig": "^2.12 || ^3.0",
8287
"vimeo/psalm": "^5.20",
83-
"rector/rector": "^0.18.2",
84-
"symfony/messenger": "^5.4 || ^6.4",
85-
"symfony/serializer": "^5.4 || ^6.4",
86-
"symfony/security-bundle": "^5.4 || ^6.4",
8788
"willdurand/hateoas-bundle": "^2.0"
8889
},
8990
"conflict": {
9091
"friendsofsymfony/rest-bundle": "<3.0",
9192
"jms/serializer-bundle": "<3.5",
92-
"willdurand/hateoas-bundle": "<2.0"
93+
"willdurand/hateoas-bundle": "<2.0 || ^2.6"
9394
},
9495
"suggest": {
9596
"doctrine/orm": "^2.5",
@@ -101,6 +102,11 @@
101102
"dealerdirect/phpcodesniffer-composer-installer": false
102103
}
103104
},
105+
"extra": {
106+
"symfony": {
107+
"require": "^6.4"
108+
}
109+
},
104110
"autoload": {
105111
"psr-4": {
106112
"Sylius\\Bundle\\ResourceBundle\\": "src/Bundle/",

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ parameters:
4444
- '/Call to method isChangeTrackingDeferredExplicit\(\) on an unknown class Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata./'
4545
- '/Call to an undefined method ReflectionClass::getAttributes\(\)./'
4646
- '/Call to an undefined method object::getRealClassName\(\)./'
47+
- '/Class Bazinga\\Bundle\\HateoasBundle\\BazingaHateoasBundle not found\./'
4748
- '/Class Doctrine\\Bundle\\MongoDBBundle/'
4849
- '/Class Doctrine\\Bundle\\PHPCRBundle/'
4950
- '/Class Doctrine\\Common\\Persistence\\ObjectManager not found\./'

psalm.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@
6767
<file name="src/Bundle/Controller/Parameters.php" />
6868
</errorLevel>
6969
</DuplicateClass>
70+
71+
<InternalClass>
72+
<errorLevel type="suppress">
73+
<file name="src/Bundle/DependencyInjection/PagerfantaExtension.php" />
74+
</errorLevel>
75+
</InternalClass>
7076

7177
<InternalMethod>
7278
<errorLevel type="suppress">
@@ -168,6 +174,12 @@
168174
</errorLevel>
169175
</PossiblyNullArgument>
170176

177+
<PossiblyNullPropertyAssignmentValue>
178+
<errorLevel type="suppress">
179+
<file name="src/Bundle/Controller/ContainerAwareTrait.php" />
180+
</errorLevel>
181+
</PossiblyNullPropertyAssignmentValue>
182+
171183
<PossiblyNullReference>
172184
<errorLevel type="suppress">
173185
<file name="src/Bundle/DependencyInjection/Configuration.php" />
@@ -198,6 +210,7 @@
198210

199211
<PropertyNotSetInConstructor>
200212
<errorLevel type="suppress">
213+
<file name="src/Bundle/Routing/ResourceLoader.php" />
201214
<file name="src/Bundle/Validator/Constraints/UniqueWithinCollectionConstraint.php" />
202215
<file name="src/Bundle/Validator/Constraints/Enabled.php" />
203216
<file name="src/Bundle/Validator/Constraints/Disabled.php" />
@@ -250,10 +263,13 @@
250263

251264
<UndefinedClass>
252265
<errorLevel type="suppress">
266+
<referencedClass name="Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle" />
253267
<referencedClass name="Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass" />
254268
<referencedClass name="Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass" />
255269
<referencedClass name="Doctrine\Common\Persistence\ObjectManager" />
256270
<referencedClass name="Doctrine\ODM\MongoDB\Mapping\ClassMetadata" />
271+
<referencedClass name="Hateoas\Configuration\Route" />
272+
<referencedClass name="Hateoas\Representation\Factory\PagerfantaFactory" />
257273
<referencedClass name="Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheAdapter" />
258274
<referencedClass name="Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface" />
259275
</errorLevel>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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\Controller;
15+
16+
use Symfony\Component\DependencyInjection\ContainerInterface;
17+
18+
/**
19+
* Copied from Symfony to keep using ResourceController as this trait has been removed in Symfony 7.
20+
* Do not use this trait on your projects, use dependency injection instead.
21+
*
22+
* @see https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/DependencyInjection/ContainerAwareTrait.php
23+
*
24+
* @internal
25+
*/
26+
trait ContainerAwareTrait
27+
{
28+
protected ?ContainerInterface $container = null;
29+
30+
public function setContainer(?ContainerInterface $container = null): void
31+
{
32+
$this->container = $container;
33+
}
34+
}

src/Bundle/Controller/Parameters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\HttpFoundation\ParameterBag;
1717
use Symfony\Component\HttpKernel\Kernel;
1818

19-
if (Kernel::MAJOR_VERSION === 6) {
19+
if (Kernel::MAJOR_VERSION >= 6) {
2020
class Parameters extends ParameterBag
2121
{
2222
/**

src/Bundle/Controller/ResourceController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use Sylius\Resource\Metadata\MetadataInterface;
2424
use Sylius\Resource\Model\ResourceInterface;
2525
use Sylius\Resource\ResourceActions;
26-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
2726
use Symfony\Component\DependencyInjection\ContainerInterface;
2827
use Symfony\Component\HttpFoundation\Request;
2928
use Symfony\Component\HttpFoundation\Response;

src/Bundle/DependencyInjection/Compiler/DoctrineTargetEntitiesResolverPass.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler;
1515

16-
use Doctrine\Common\EventSubscriber;
1716
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\Helper\TargetEntitiesResolverInterface;
1817
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1918
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -47,13 +46,7 @@ public function process(ContainerBuilder $container): void
4746
$resolveTargetEntityListener->addMethodCall('addResolveTargetEntity', [$interface, $model, []]);
4847
}
4948

50-
/** @var object|string $resolveTargetEntityListenerClass */
51-
$resolveTargetEntityListenerClass = $container->getParameterBag()->resolveValue($resolveTargetEntityListener->getClass());
52-
if (is_a($resolveTargetEntityListenerClass, EventSubscriber::class, true)) {
53-
if (!$resolveTargetEntityListener->hasTag('doctrine.event_subscriber')) {
54-
$resolveTargetEntityListener->addTag('doctrine.event_subscriber');
55-
}
56-
} elseif (!$resolveTargetEntityListener->hasTag('doctrine.event_listener')) {
49+
if (!$resolveTargetEntityListener->hasTag('doctrine.event_listener')) {
5750
$resolveTargetEntityListener->addTag('doctrine.event_listener', ['event' => 'loadClassMetadata']);
5851
}
5952
}

0 commit comments

Comments
 (0)