Skip to content

Commit

Permalink
feature #863 Adding support for Symfony 7 (loic425)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
GSadee authored Sep 5, 2024
2 parents 851babc + 7371171 commit 2a908ba
Show file tree
Hide file tree
Showing 47 changed files with 478 additions and 215 deletions.
25 changes: 20 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
tests:
runs-on: ubuntu-latest
name: "PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, Twig ${{ matrix.twig }}, Persistence: ${{ matrix.persistence }}, Collections: ${{ matrix.collections }}"
env:
APP_ENV: ${{ matrix.app_env }}
strategy:
fail-fast: false
matrix:
Expand All @@ -22,10 +24,15 @@ jobs:
symfony: ["^5.4", "^6.4"]
persistence: ["^2.0", "^3.0"]
collections: ["^1.8", "^2.0"]
app_env: ["test"]
include:
- php: "8.1"
pagerfanta: "^3.7"
symfony: "^5.4"
app_env: "test"
- php: "8.3"
symfony: "^7.0"
app_env: "test_without_hateoas"
exclude:
- php: "8.1"
collections: "^2.0"
Expand Down Expand Up @@ -82,6 +89,11 @@ jobs:
if: matrix.collections != ''
run: composer require "doctrine/collections:${{ matrix.collections }}" --no-update --no-scripts

-
name: Remove hateoas on Symfony 7
if: matrix.symfony == '^7.0'
run: composer remove --dev willdurand/hateoas-bundle --no-update --no-scripts

-
name: Install dependencies
run: |
Expand Down Expand Up @@ -124,7 +136,7 @@ jobs:
if: ${{ true != contains( matrix.php, '8.2' ) }}
run: |
sed -i -e 's/state_machine_component: symfony/state_machine_component: winzou/g' tests/Application/config/packages/test/sylius_resource.yaml
(cd tests/Application && bin/console cache:clear --env=test)
(cd tests/Application && bin/console cache:clear)
vendor/bin/phpspec run --ansi --no-interaction
sed -i -e 's/state_machine_component: winzou/state_machine_component: symfony/g' tests/Application/config/packages/test/sylius_resource.yaml
Expand All @@ -133,7 +145,7 @@ jobs:
name: Run state machine PHPUnit tests with winzou/state-machine package
run: |
sed -i -e 's/state_machine_component: symfony/state_machine_component: winzou/g' tests/Application/config/packages/test/sylius_resource.yaml
(cd tests/Application && bin/console cache:clear --env=test)
(cd tests/Application && bin/console cache:clear)
vendor/bin/phpunit --colors=always
sed -i -e 's/state_machine_component: winzou/state_machine_component: symfony/g' tests/Application/config/packages/test/sylius_resource.yaml
Expand All @@ -142,28 +154,30 @@ jobs:
if: ${{ true != contains( matrix.php, '8.2' ) }}
run: |
sed -i -e 's/state_machine_component: winzou/state_machine_component: symfony/g' tests/Application/config/packages/test/sylius_resource.yaml
(cd tests/Application && bin/console cache:clear --env=test)
(cd tests/Application && bin/console cache:clear)
vendor/bin/phpspec run --ansi --no-interaction
sed -i -e 's/state_machine_component: symfony/state_machine_component: winzou/g' tests/Application/config/packages/test/sylius_resource.yaml
-
name: Run state machine PHPUnit tests with symfony/workflow package
run: |
sed -i -e 's/state_machine_component: winzou/state_machine_component: symfony/g' tests/Application/config/packages/test/sylius_resource.yaml
(cd tests/Application && bin/console cache:clear --env=test)
(cd tests/Application && bin/console cache:clear)
vendor/bin/phpunit --colors=always
sed -i -e 's/state_machine_component: symfony/state_machine_component: winzou/g' tests/Application/config/packages/test/sylius_resource.yaml
-
name: Run lint container without friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle packages
if: matrix.app_env == 'test'
run: |
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
composer require --dev friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts
-
name: Run lint container without winzou/state-machine-bundle package
if: matrix.app_env == 'test'
run: |
composer remove winzou/state-machine-bundle --no-scripts
(cd tests/Application && bin/console cache:clear --env=test_without_state_machine)
Expand All @@ -172,6 +186,7 @@ jobs:
-
name: Run lint container without twig/twig package
if: matrix.app_env == 'test'
run: |
composer remove symfony/twig-bundle --no-scripts
composer remove sylius/grid-bundle --no-scripts --dev
Expand Down
5 changes: 5 additions & 0 deletions CONFLICTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@

This document explains why certain conflicts were added to `composer.json` and
references related issues.

- `willdurand/hateoas-bundle: ^2.6`

This version allows Symfony 7 but does not support the "annotation_reader" service removal.
@see /~https://github.com/willdurand/BazingaHateoasBundle/issues/108
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ COPY . /app

WORKDIR /app

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

WORKDIR /app/tests/Application
Expand Down
62 changes: 34 additions & 28 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@
"doctrine/annotations": "^2.0",
"doctrine/collections": "^1.8 || ^2.0",
"doctrine/doctrine-bundle": "^2.0",
"doctrine/event-manager": "^1.1",
"doctrine/event-manager": "^1.1 || ^2.0",
"doctrine/inflector": "^1.4 || ^2.0",
"doctrine/persistence": "^2.0 || ^3.0",
"gedmo/doctrine-extensions": "^2.4.12 || ^3.0",
"sylius/registry": "^1.2",
"symfony/config": "^5.4 || ^6.4",
"symfony/config": "^5.4 || ^6.4 || ^7.0",
"symfony/deprecation-contracts": "^2.1 || ^3.0",
"symfony/expression-language": "^5.4 || ^6.4",
"symfony/form": "^5.4 || ^6.4",
"symfony/framework-bundle": "^5.4 || ^6.4",
"symfony/http-foundation": "^5.4 || ^6.4",
"symfony/intl": "^5.4 || ^6.4",
"symfony/security-core": "^5.4 || ^6.4",
"symfony/security-csrf": "^5.4 || ^6.4",
"symfony/routing": "^5.4 || ^6.4",
"symfony/translation": "^5.4 || ^6.4",
"symfony/twig-bundle": "^5.4 || ^6.4",
"symfony/validator": "^5.4 || ^6.4",
"symfony/yaml": "^5.4 || ^6.4",
"symfony/expression-language": "^5.4 || ^6.4 || ^7.0",
"symfony/form": "^5.4 || ^6.4 || ^7.0",
"symfony/framework-bundle": "^5.4 || ^6.4 || ^7.0",
"symfony/http-foundation": "^5.4 || ^6.4 || ^7.0",
"symfony/intl": "^5.4 || ^6.4 || ^7.0",
"symfony/security-core": "^5.4 || ^6.4 || ^7.0",
"symfony/security-csrf": "^5.4 || ^6.4 || ^7.0",
"symfony/routing": "^5.4 || ^6.4 || ^7.0",
"symfony/translation": "^5.4 || ^6.4 || ^7.0",
"symfony/twig-bundle": "^5.4 || ^6.4 || ^7.0",
"symfony/validator": "^5.4 || ^6.4 || ^7.0",
"symfony/yaml": "^5.4 || ^6.4 || ^7.0",
"webmozart/assert": "^1.8",
"winzou/state-machine-bundle": "^0.6",
"winzou/state-machine-bundle": "^0.6.2",
"willdurand/negotiation": "^3.1"
},
"replace": {
Expand All @@ -61,7 +61,7 @@
"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",
"matthiasnoback/symfony-dependency-injection-test": "^4.2.1 || ^5.1",
"pagerfanta/pagerfanta": "^3.7 || ^4.0",
"pamil/phpspec-skip-example-extension": "^4.2",
"phpspec/phpspec": "^7.3",
Expand All @@ -70,26 +70,27 @@
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.18.2",
"sylius-labs/coding-standard": "^4.0",
"sylius/grid-bundle": "^1.7 || v1.12.0-ALPHA.1",
"symfony/console": "^5.4 || ^6.4",
"symfony/dependency-injection": "^5.4 || ^6.4",
"symfony/dotenv": "^5.4 || ^6.4",
"symfony/stopwatch": "^5.4 || ^6.4",
"symfony/uid": "^5.4 || ^6.4",
"symfony/workflow": "^5.4 || ^6.4",
"sylius/grid-bundle": "^1.7 || dev-symfony-7",
"symfony/console": "^5.4 || ^6.4 || ^7.0",
"symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0",
"symfony/dotenv": "^5.4 || ^6.4 || ^7.0",
"symfony/http-kernel": "^5.4 || ^6.4 || ^7.0",
"symfony/stopwatch": "^5.4 || ^6.4 || ^7.0",
"symfony/uid": "^5.4 || ^6.4 || ^7.0",
"symfony/workflow": "^5.4 || ^6.4 || ^7.0",
"symfony/messenger": "^5.4 || ^6.4 || ^7.0",
"symfony/serializer": "^5.4 || ^6.4 || ^7.0",
"symfony/security-bundle": "^5.4 || ^6.4 || ^7.0",
"twig/twig": "^2.12 || ^3.0",
"vimeo/psalm": "^5.20",
"rector/rector": "^0.18.2",
"symfony/messenger": "^5.4 || ^6.4",
"symfony/serializer": "^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"
"willdurand/hateoas-bundle": "<2.0 || ^2.6"
},
"suggest": {
"doctrine/orm": "^2.5",
Expand All @@ -101,6 +102,11 @@
"dealerdirect/phpcodesniffer-composer-installer": false
}
},
"extra": {
"symfony": {
"require": "^6.4"
}
},
"autoload": {
"psr-4": {
"Sylius\\Bundle\\ResourceBundle\\": "src/Bundle/",
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ parameters:
- '/Call to method isChangeTrackingDeferredExplicit\(\) on an unknown class Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata./'
- '/Call to an undefined method ReflectionClass::getAttributes\(\)./'
- '/Call to an undefined method object::getRealClassName\(\)./'
- '/Class Bazinga\\Bundle\\HateoasBundle\\BazingaHateoasBundle not found\./'
- '/Class Doctrine\\Bundle\\MongoDBBundle/'
- '/Class Doctrine\\Bundle\\PHPCRBundle/'
- '/Class Doctrine\\Common\\Persistence\\ObjectManager not found\./'
Expand Down
16 changes: 16 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
<file name="src/Bundle/Controller/Parameters.php" />
</errorLevel>
</DuplicateClass>

<InternalClass>
<errorLevel type="suppress">
<file name="src/Bundle/DependencyInjection/PagerfantaExtension.php" />
</errorLevel>
</InternalClass>

<InternalMethod>
<errorLevel type="suppress">
Expand Down Expand Up @@ -168,6 +174,12 @@
</errorLevel>
</PossiblyNullArgument>

<PossiblyNullPropertyAssignmentValue>
<errorLevel type="suppress">
<file name="src/Bundle/Controller/ContainerAwareTrait.php" />
</errorLevel>
</PossiblyNullPropertyAssignmentValue>

<PossiblyNullReference>
<errorLevel type="suppress">
<file name="src/Bundle/DependencyInjection/Configuration.php" />
Expand Down Expand Up @@ -198,6 +210,7 @@

<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<file name="src/Bundle/Routing/ResourceLoader.php" />
<file name="src/Bundle/Validator/Constraints/UniqueWithinCollectionConstraint.php" />
<file name="src/Bundle/Validator/Constraints/Enabled.php" />
<file name="src/Bundle/Validator/Constraints/Disabled.php" />
Expand Down Expand Up @@ -250,10 +263,13 @@

<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle" />
<referencedClass name="Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass" />
<referencedClass name="Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass" />
<referencedClass name="Doctrine\Common\Persistence\ObjectManager" />
<referencedClass name="Doctrine\ODM\MongoDB\Mapping\ClassMetadata" />
<referencedClass name="Hateoas\Configuration\Route" />
<referencedClass name="Hateoas\Representation\Factory\PagerfantaFactory" />
<referencedClass name="Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheAdapter" />
<referencedClass name="Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface" />
</errorLevel>
Expand Down
34 changes: 34 additions & 0 deletions src/Bundle/Controller/ContainerAwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\ResourceBundle\Controller;

use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Copied from Symfony to keep using ResourceController as this trait has been removed in Symfony 7.
* Do not use this trait on your projects, use dependency injection instead.
*
* @see /~https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/DependencyInjection/ContainerAwareTrait.php
*
* @internal
*/
trait ContainerAwareTrait
{
protected ?ContainerInterface $container = null;

public function setContainer(?ContainerInterface $container = null): void
{
$this->container = $container;
}
}
2 changes: 1 addition & 1 deletion src/Bundle/Controller/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpKernel\Kernel;

if (Kernel::MAJOR_VERSION === 6) {
if (Kernel::MAJOR_VERSION >= 6) {
class Parameters extends ParameterBag
{
/**
Expand Down
1 change: 0 additions & 1 deletion src/Bundle/Controller/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Sylius\Resource\Metadata\MetadataInterface;
use Sylius\Resource\Model\ResourceInterface;
use Sylius\Resource\ResourceActions;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler;

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

/** @var object|string $resolveTargetEntityListenerClass */
$resolveTargetEntityListenerClass = $container->getParameterBag()->resolveValue($resolveTargetEntityListener->getClass());
if (is_a($resolveTargetEntityListenerClass, EventSubscriber::class, true)) {
if (!$resolveTargetEntityListener->hasTag('doctrine.event_subscriber')) {
$resolveTargetEntityListener->addTag('doctrine.event_subscriber');
}
} elseif (!$resolveTargetEntityListener->hasTag('doctrine.event_listener')) {
if (!$resolveTargetEntityListener->hasTag('doctrine.event_listener')) {
$resolveTargetEntityListener->addTag('doctrine.event_listener', ['event' => 'loadClassMetadata']);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ public function __construct(RepositoryInterface $repository, ?string $identifier
}

/**
* @psalm-suppress MissingParamType
*
* @param object|null $value
*
* @return mixed
* @inheritDoc
*/
public function transform($value)
public function transform(mixed $value): mixed
{
if (null === $value) {
return null;
Expand All @@ -51,8 +47,10 @@ public function transform($value)
return PropertyAccess::createPropertyAccessor()->getValue($value, $this->identifier);
}

/** @param int|string|null $value */
public function reverseTransform($value): ?ResourceInterface
/**
* @inheritDoc
*/
public function reverseTransform(mixed $value): ?ResourceInterface
{
if (null === $value) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
<service id="sylius.translation.translatable_listener.doctrine.orm" class="Sylius\Bundle\ResourceBundle\EventListener\ORMTranslatableListener">
<argument type="service" id="sylius.resource_registry" />
<argument type="service" id="sylius.translatable_entity_locale_assigner" />
<tag name="doctrine.event_subscriber" connection="default" priority="99" />
<tag name="doctrine.event_listener" connection="default" event="loadClassMetadata" priority="99" />
<tag name="doctrine.event_listener" connection="default" event="postLoad" priority="99" />
</service>
<service id="Sylius\Bundle\ResourceBundle\EventListener\ORMTranslatableListener" alias="sylius.translation.translatable_listener.doctrine.orm" />

Expand Down
1 change: 1 addition & 0 deletions src/Bundle/Resources/config/services/routing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<argument type="service">
<service class="Sylius\Bundle\ResourceBundle\Routing\RouteFactory" />
</argument>
<argument>%kernel.environment%</argument>
<tag name="routing.loader" />
</service>
<service id="Sylius\Bundle\ResourceBundle\Routing\ResourceLoader" alias="sylius.routing.loader.resource" public="false" />
Expand Down
Loading

0 comments on commit 2a908ba

Please sign in to comment.