Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adding support for Symfony 7 #863

Draft
wants to merge 35 commits into
base: 1.12
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
09f7130
Move fos rest, jms serializer and hateoas on dev requirements
loic425 May 15, 2024
f3b4b74
Add tests for compiler passes
loic425 May 15, 2024
2bf5833
Fix step name
loic425 May 15, 2024
bbe3741
Apply suggestions from code review
loic425 May 16, 2024
bb3aeae
Rename compiler passes
loic425 May 16, 2024
290f142
Allow SF7 on dependencies
loic425 May 23, 2024
281ac9d
SF7 Fix the sf7 build
loic425 May 23, 2024
47f926e
Merge pull request #888 from loic425/fix/the-sf7-build
loic425 May 29, 2024
7e0d2eb
Bump symfony-dependency-injection-test
loic425 May 23, 2024
db97227
Merge pull request #879 from loic425/bump-symfony-dependency-injectio…
loic425 May 29, 2024
8d1fd4c
[SF7] Bump grid version
loic425 May 23, 2024
37a091a
Merge pull request #882 from loic425/sf7/bump-grid-version
loic425 May 29, 2024
3a28e67
[SF7] Bump Doctrine event manager version
loic425 May 23, 2024
0e2643f
Merge pull request #884 from loic425/sf7/bump-doctrine-event-manager-…
loic425 May 29, 2024
7f8504c
[SF7] Add removed symfony container aware trait
loic425 May 23, 2024
e6e3091
Merge pull request #885 from loic425/sf7/fix-container-aware-trait
loic425 May 29, 2024
f27f93b
[SF7] Remove enable authenticator manager option on test application
loic425 May 23, 2024
4d0c2e1
Merge pull request #881 from loic425/sf7/remove-enable-authentication…
loic425 May 29, 2024
ebac2c9
Upgrade winzou on dev branch
loic425 May 23, 2024
3baa1b8
Merge pull request #886 from loic425/sf7/upgrade-winzou-on-dev-branch
loic425 May 29, 2024
5609c1f
[SF7] Remove hateoas on Symfony 7
loic425 May 23, 2024
7f374bd
Merge pull request #887 from loic425/sf7/remove-hateoas
loic425 May 29, 2024
8d2e528
[SF7] Fix resource loader
loic425 May 23, 2024
da5f740
Use abstract loader from Symfony
loic425 May 29, 2024
06dc029
Merge pull request #890 from loic425/fix/resource-loader
loic425 May 29, 2024
ce59b1d
Fix analysis errors
loic425 May 23, 2024
5ff7ee8
Fix PHPStan errors
loic425 May 23, 2024
49bbf3f
Add suggestion from code review
loic425 May 29, 2024
28fee40
Merge pull request #891 from loic425/fix/psalm-errors
loic425 May 30, 2024
e1c2ff4
[SF7] Fix phpspec tests
loic425 May 24, 2024
af37c1e
Merge pull request #892 from loic425/sf7/fix-phpspec-errors
loic425 May 30, 2024
3172eab
[SF7] Fix PHPUnit tests
loic425 May 27, 2024
f55e5aa
Merge pull request #894 from loic425/sf7/fix-phpunit-tests
loic425 May 30, 2024
27890ef
[SF7] Bump Winzou state machine version
loic425 May 31, 2024
2421a3d
Merge pull request #897 from loic425/sf7/bump-winzou-state-machine-ve…
loic425 May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ on:
jobs:
tests:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
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 +25,18 @@ jobs:
symfony: ["^5.4", "^6.4"]
persistence: ["^2.0", "^3.0"]
collections: ["^1.8", "^2.0"]
experimental: [false]
app_env: ["test"]
include:
- php: "8.1"
pagerfanta: "^3.7"
symfony: "^5.4"
app_env: "test"
experimental: false
- php: 8.3
symfony: "^7.0"
app_env: "test_without_hateoas"
experimental: true
exclude:
- php: "8.1"
collections: "^2.0"
Expand Down Expand Up @@ -82,6 +93,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 +140,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 +149,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,27 +158,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 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
if: matrix.app_env == 'test'
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)
composer require friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts
(cd tests/Application && bin/console lint:container --env=test_without_fosrest)
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 @@ -171,6 +190,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
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
10 changes: 10 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
69 changes: 39 additions & 30 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,38 @@
"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",
"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/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",
"willdurand/hateoas-bundle": "^2.0",
"winzou/state-machine-bundle": "^0.6",
"winzou/state-machine-bundle": "^0.6.2",
"willdurand/negotiation": "^3.1"
},
"replace": {
"sylius/resource": "self.version"
},
"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",
"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 @@ -71,20 +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 || ^2.6"
},
"suggest": {
"doctrine/orm": "^2.5",
Expand All @@ -99,6 +105,9 @@
"extra": {
"branch-alias": {
"dev-master": "1.10-dev"
},
"symfony": {
"require": "^6.4"
}
},
"autoload": {
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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
10 changes: 10 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,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 +204,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 +257,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
16 changes: 8 additions & 8 deletions src/Bundle/Controller/ResourcesCollectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

/**
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions src/Bundle/Controller/ViewHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@

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
{
if (!$requestConfiguration->isHtmlRequest()) {
$this->restViewHandler->setExclusionStrategyGroups($requestConfiguration->getSerializationGroups() ?? []);

if ($version = $requestConfiguration->getSerializationVersion()) {
$version = $requestConfiguration->getSerializationVersion();
if (null !== $version) {
$this->restViewHandler->setExclusionStrategyVersion($version);
}

Expand Down
Loading
Loading