From ccb9b7bf3bac90676c87c2dc2f64ac56c295f3cd Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 3 Dec 2021 06:54:52 +0100 Subject: [PATCH] feature #13339 Add Support for Symfony 5.4 (AdamKasp) This PR was merged into the 1.11-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? |yes | BC breaks? | no | Deprecations? | no | License | MIT Commits ------- 28a02a6a620f68a033dc25650f18380ece514c51 Prepare Sylius for support Symfony 5.4 d2c39e4059350f648b11874894740773c01308a7 remove usage of symfony internal method fef624340b5367f9cbb3dd9765de5f6eaf969e29 bump symofny verion from 5.4.0-RC1 to 5.4 63395281c3de2b19ebce99090a206f4e0fa014b8 update argument in UsernamePasswordToken 2964e0ed9d31864d4b7248e2e546ef16de193535 make workorounds over deprecated method in symofny 5.4 --- .github/workflows/application.yml | 8 ++--- .github/workflows/packages.yml | 2 +- psalm.xml | 3 ++ src/Sylius/Behat/Service/SecurityService.php | 8 ++++- .../Bundle/AddressingBundle/composer.json | 4 +-- src/Sylius/Bundle/AdminBundle/composer.json | 2 +- .../Payment/GetPaymentConfiguration.php | 5 ++- .../Controller/UploadAvatarImageAction.php | 2 +- src/Sylius/Bundle/ApiBundle/composer.json | 2 +- .../Bundle/AttributeBundle/composer.json | 4 +-- src/Sylius/Bundle/ChannelBundle/composer.json | 2 +- .../CoreBundle/Command/SetupCommand.php | 4 +-- .../Controller/ProductTaxonController.php | 33 +++++++++++++++-- .../Controller/ProductVariantController.php | 26 +++++++++++++- .../CoreBundle/Resources/config/services.xml | 2 ++ .../CoreBundle/Security/UserImpersonator.php | 22 ++++++++---- src/Sylius/Bundle/CoreBundle/composer.json | 2 +- .../Bundle/CurrencyBundle/composer.json | 2 +- .../Bundle/CustomerBundle/composer.json | 2 +- .../Bundle/InventoryBundle/composer.json | 2 +- src/Sylius/Bundle/LocaleBundle/composer.json | 2 +- .../Controller/OrderController.php | 28 ++++++++++++++- src/Sylius/Bundle/OrderBundle/composer.json | 4 +-- src/Sylius/Bundle/PaymentBundle/composer.json | 4 +-- src/Sylius/Bundle/PayumBundle/composer.json | 2 +- .../Controller/ProductSlugController.php | 21 +++++++++++ .../Resources/config/services.xml | 1 + src/Sylius/Bundle/ProductBundle/composer.json | 4 +-- .../Bundle/PromotionBundle/composer.json | 4 +-- src/Sylius/Bundle/ReviewBundle/composer.json | 2 +- .../Bundle/ShippingBundle/composer.json | 4 +-- src/Sylius/Bundle/ShopBundle/composer.json | 2 +- .../Bundle/TaxationBundle/composer.json | 4 +-- .../Bundle/TaxonomyBundle/composer.json | 4 +-- .../Controller/SecurityController.php | 36 +++++++++++++++++-- .../UserBundle/Resources/config/services.xml | 2 ++ .../Bundle/UserBundle/Security/UserLogin.php | 9 +++++ src/Sylius/Component/Addressing/composer.json | 2 +- src/Sylius/Component/Attribute/composer.json | 2 +- src/Sylius/Component/Core/composer.json | 2 +- src/Sylius/Component/Shipping/composer.json | 2 +- src/Sylius/Component/User/composer.json | 2 +- tests/Controller/AdminProductAjaxTest.php | 9 ++++- 43 files changed, 231 insertions(+), 58 deletions(-) diff --git a/.github/workflows/application.yml b/.github/workflows/application.yml index 4fe81098fcf..9b78ce6196c 100644 --- a/.github/workflows/application.yml +++ b/.github/workflows/application.yml @@ -20,7 +20,7 @@ on: cron: "0 1 * * 6" # Run at 1am every Saturday workflow_dispatch: ~ -jobs: +jobsg a static-checks: runs-on: ubuntu-latest @@ -32,7 +32,7 @@ jobs: fail-fast: false matrix: php: ["7.4", "8.0"] - symfony: ["^4.4", "5.2.*", "5.3.*"] + symfony: ["^4.4", "5.2.*", "5.3.*", "5.4.*"] steps: - @@ -120,7 +120,7 @@ jobs: fail-fast: false matrix: php: ["7.4", "8.0"] - symfony: ["^4.4", "5.2.*", "5.3.*"] + symfony: ["^4.4", "5.2.*", "5.3.*", "5.4.*"] node: ["14.x"] mysql: ["5.7", "8.0"] @@ -249,7 +249,7 @@ jobs: fail-fast: false matrix: php: ["7.4", "8.0"] - symfony: ["^4.4", "5.2.*", "5.3.*"] + symfony: ["^4.4", "5.2.*", "5.3.*", "5.4.*"] node: ["14.x"] mysql: ["5.7", "8.0"] diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml index 4a67181b032..890687e10fd 100644 --- a/.github/workflows/packages.yml +++ b/.github/workflows/packages.yml @@ -49,7 +49,7 @@ jobs: fail-fast: false matrix: php: ["7.4", "8.0"] - symfony: ["^4.4", "5.2.*"] + symfony: ["^4.4", "5.2.*", "5.3.*", "5.4.*"] package: "${{ fromJson(needs.list.outputs.packages) }}" steps: diff --git a/psalm.xml b/psalm.xml index 6a3b1a02d0f..341583d2a8d 100644 --- a/psalm.xml +++ b/psalm.xml @@ -119,6 +119,7 @@ + @@ -202,6 +203,7 @@ + @@ -225,6 +227,7 @@ + diff --git a/src/Sylius/Behat/Service/SecurityService.php b/src/Sylius/Behat/Service/SecurityService.php index 3afef083348..6c2baa63dbb 100644 --- a/src/Sylius/Behat/Service/SecurityService.php +++ b/src/Sylius/Behat/Service/SecurityService.php @@ -43,7 +43,13 @@ public function __construct(SessionInterface $session, CookieSetterInterface $co public function logIn(UserInterface $user): void { - $token = new UsernamePasswordToken($user, $user->getPassword(), $this->firewallContextName, $user->getRoles()); + /** @deprecated parameter credential was deprecated in Symfony 5.4, so in Sylius 1.11 too, in Sylius 2.0 providing 4 arguments will be prohibited. */ + if (3 === (new \ReflectionClass(UsernamePasswordToken::class))->getConstructor()->getNumberOfParameters()) { + $token = new UsernamePasswordToken($user, $this->firewallContextName, $user->getRoles()); + } else { + $token = new UsernamePasswordToken($user, $user->getPassword(), $this->firewallContextName, $user->getRoles()); + } + $this->setToken($token); } diff --git a/src/Sylius/Bundle/AddressingBundle/composer.json b/src/Sylius/Bundle/AddressingBundle/composer.json index 375fc301212..dbbd169e8ad 100644 --- a/src/Sylius/Bundle/AddressingBundle/composer.json +++ b/src/Sylius/Bundle/AddressingBundle/composer.json @@ -31,7 +31,7 @@ "sylius/addressing": "^1.6", "sylius/resource-bundle": "^1.7", "symfony/framework-bundle": "^4.4 || ^5.2", - "symfony/intl": "^4.4 || ^5.2" + "symfony/intl": "^4.4 || ^5.4" }, "conflict": { "twig/twig": "^1.0 || ^3.0" @@ -44,7 +44,7 @@ "symfony/browser-kit": "^4.4 || ^5.2", "symfony/dependency-injection": "^4.4 || ^5.2", "symfony/form": "^4.4 || ^5.2", - "symfony/validator": "^4.4 || ^5.2" + "symfony/validator": "^4.4 || ^5.4" }, "config": { "bin-dir": "bin" diff --git a/src/Sylius/Bundle/AdminBundle/composer.json b/src/Sylius/Bundle/AdminBundle/composer.json index 3775e61b0d3..e6066e2fcbf 100644 --- a/src/Sylius/Bundle/AdminBundle/composer.json +++ b/src/Sylius/Bundle/AdminBundle/composer.json @@ -40,7 +40,7 @@ "require-dev": { "phpspec/phpspec": "^7.0", "phpunit/phpunit": "^8.5", - "symfony/dependency-injection": "^4.4 || ^5.2" + "symfony/dependency-injection": "^4.4 || ^5.4" }, "config": { "bin-dir": "bin" diff --git a/src/Sylius/Bundle/ApiBundle/Controller/Payment/GetPaymentConfiguration.php b/src/Sylius/Bundle/ApiBundle/Controller/Payment/GetPaymentConfiguration.php index ad2ad8dbae2..79086fcb86e 100644 --- a/src/Sylius/Bundle/ApiBundle/Controller/Payment/GetPaymentConfiguration.php +++ b/src/Sylius/Bundle/ApiBundle/Controller/Payment/GetPaymentConfiguration.php @@ -38,7 +38,10 @@ public function __construct( public function __invoke(Request $request): JsonResponse { /** @var PaymentInterface|null $payment */ - $payment = $this->paymentRepository->findOneByOrderToken($request->get('paymentId'), $request->get('id')); + $payment = $this->paymentRepository->findOneByOrderToken( + $request->attributes->get('paymentId'), + $request->attributes->get('id') + ); Assert::notNull($payment); diff --git a/src/Sylius/Bundle/ApiBundle/Controller/UploadAvatarImageAction.php b/src/Sylius/Bundle/ApiBundle/Controller/UploadAvatarImageAction.php index 450eab7f456..02414b4719e 100644 --- a/src/Sylius/Bundle/ApiBundle/Controller/UploadAvatarImageAction.php +++ b/src/Sylius/Bundle/ApiBundle/Controller/UploadAvatarImageAction.php @@ -57,7 +57,7 @@ public function __invoke(Request $request): ImageInterface $image->setFile($file); /** @var string $ownerIri */ - $ownerIri = $request->get('owner'); + $ownerIri = $request->request->get('owner'); Assert::notEmpty($ownerIri); /** @var ResourceInterface|AdminUserInterface $owner */ diff --git a/src/Sylius/Bundle/ApiBundle/composer.json b/src/Sylius/Bundle/ApiBundle/composer.json index 4c08b9829fe..aa8687cbd59 100644 --- a/src/Sylius/Bundle/ApiBundle/composer.json +++ b/src/Sylius/Bundle/ApiBundle/composer.json @@ -28,7 +28,7 @@ "api-platform/core": "^2.6", "lexik/jwt-authentication-bundle": "^2.6", "sylius/core-bundle": "^1.7", - "symfony/messenger": "^4.4 || ^5.2" + "symfony/messenger": "^4.4 || ^5.4" }, "require-dev": { "matthiasnoback/symfony-config-test": "^4.2", diff --git a/src/Sylius/Bundle/AttributeBundle/composer.json b/src/Sylius/Bundle/AttributeBundle/composer.json index 4e898d0cd9c..05784617e19 100644 --- a/src/Sylius/Bundle/AttributeBundle/composer.json +++ b/src/Sylius/Bundle/AttributeBundle/composer.json @@ -31,7 +31,7 @@ "stof/doctrine-extensions-bundle": "^1.4", "sylius/attribute": "^1.6", "sylius/resource-bundle": "^1.7", - "symfony/framework-bundle": "^4.4 || ^5.2" + "symfony/framework-bundle": "^4.4 || ^5.4" }, "require-dev": { "doctrine/orm": "^2.7", @@ -39,7 +39,7 @@ "phpunit/phpunit": "^8.5", "symfony/browser-kit": "^4.4 || ^5.2", "symfony/dependency-injection": "^4.4 || ^5.2", - "symfony/form": "^4.4 || ^5.2" + "symfony/form": "^4.4 || ^5.4" }, "config": { "bin-dir": "bin" diff --git a/src/Sylius/Bundle/ChannelBundle/composer.json b/src/Sylius/Bundle/ChannelBundle/composer.json index 16abd4b25ac..b67d819d75b 100644 --- a/src/Sylius/Bundle/ChannelBundle/composer.json +++ b/src/Sylius/Bundle/ChannelBundle/composer.json @@ -28,7 +28,7 @@ "php": "^7.4 || ^8.0", "sylius/channel": "^1.6", "sylius/resource-bundle": "^1.7", - "symfony/framework-bundle": "^4.4 || ^5.2" + "symfony/framework-bundle": "^4.4 || ^5.4" }, "require-dev": { "doctrine/orm": "^2.7", diff --git a/src/Sylius/Bundle/CoreBundle/Command/SetupCommand.php b/src/Sylius/Bundle/CoreBundle/Command/SetupCommand.php index 2a055ac5217..4e76e2c112b 100644 --- a/src/Sylius/Bundle/CoreBundle/Command/SetupCommand.php +++ b/src/Sylius/Bundle/CoreBundle/Command/SetupCommand.php @@ -112,7 +112,7 @@ function ($value): string { /** @var ConstraintViolationListInterface $errors */ $errors = $this->getContainer()->get('validator')->validate((string) $value, [new Email(), new NotBlank()]); foreach ($errors as $error) { - throw new \DomainException($error->getMessage()); + throw new \DomainException((string) $error->getMessage()); } return $value; @@ -191,7 +191,7 @@ function ($value): string { /** @var ConstraintViolationListInterface $errors */ $errors = $this->getContainer()->get('validator')->validate($value, [new NotBlank()]); foreach ($errors as $error) { - throw new \DomainException($error->getMessage()); + throw new \DomainException((string) $error->getMessage()); } return $value; diff --git a/src/Sylius/Bundle/CoreBundle/Controller/ProductTaxonController.php b/src/Sylius/Bundle/CoreBundle/Controller/ProductTaxonController.php index d060dbcf50a..5de2e5ae817 100644 --- a/src/Sylius/Bundle/CoreBundle/Controller/ProductTaxonController.php +++ b/src/Sylius/Bundle/CoreBundle/Controller/ProductTaxonController.php @@ -30,13 +30,14 @@ class ProductTaxonController extends ResourceController * @throws HttpException * * @deprecated This ajax action is deprecated and will be removed in Sylius 2.0 - use ProductTaxonController::updateProductTaxonsPositionsAction instead. + * + * @psalm-suppress DeprecatedMethod */ public function updatePositionsAction(Request $request): Response { $configuration = $this->requestConfigurationFactory->create($this->metadata, $request); $this->isGrantedOr403($configuration, ResourceActions::UPDATE); - $productTaxons = $request->get('productTaxons'); - + $productTaxons = $this->getParameterFromRequest($request,'productTaxons'); $this->validateCsrfProtection($request, $configuration); if ($this->shouldProductsPositionsBeUpdated($request, $productTaxons)) { @@ -55,11 +56,14 @@ public function updatePositionsAction(Request $request): Response return new JsonResponse(); } + /** + * @psalm-suppress DeprecatedMethod + */ public function updateProductTaxonsPositionsAction(Request $request): Response { $configuration = $this->requestConfigurationFactory->create($this->metadata, $request); $this->isGrantedOr403($configuration, ResourceActions::UPDATE); - $productTaxons = $request->get('productTaxons'); + $productTaxons = $this->getParameterFromRequest($request,'productTaxons'); $this->validateCsrfProtection($request, $configuration); @@ -103,4 +107,27 @@ private function updatePositions(string $position, int $id): void $productTaxonFromBase = $this->repository->findOneBy(['id' => $id]); $productTaxonFromBase->setPosition((int) $position); } + + /** + * @return mixed + * + * @deprecated This function will be removed in Sylius 2.0, since Symfony 5.4, use explicit input sources instead + * based on Symfony\Component\HttpFoundation\Request::get + */ + private function getParameterFromRequest(Request $request, string $key) + { + if ($request !== $result = $request->attributes->get($key, $request)) { + return $result; + } + + if ($request->query->has($key)) { + return $request->query->all()[$key]; + } + + if ($request->request->has($key)) { + return $request->request->all()[$key]; + } + + return null; + } } diff --git a/src/Sylius/Bundle/CoreBundle/Controller/ProductVariantController.php b/src/Sylius/Bundle/CoreBundle/Controller/ProductVariantController.php index 10cb62d5d6a..2e1bd17e763 100644 --- a/src/Sylius/Bundle/CoreBundle/Controller/ProductVariantController.php +++ b/src/Sylius/Bundle/CoreBundle/Controller/ProductVariantController.php @@ -25,12 +25,13 @@ class ProductVariantController extends ResourceController { /** * @throws HttpException + * @psalm-suppress DeprecatedMethod */ public function updatePositionsAction(Request $request): Response { $configuration = $this->requestConfigurationFactory->create($this->metadata, $request); $this->isGrantedOr403($configuration, ResourceActions::UPDATE); - $productVariantsToUpdate = $request->get('productVariants'); + $productVariantsToUpdate = $this->getParameterFromRequest($request, 'productVariants'); if ($configuration->isCsrfProtectionEnabled() && !$this->isCsrfTokenValid('update-product-variant-position', (string) $request->request->get('_csrf_token'))) { throw new HttpException(Response::HTTP_FORBIDDEN, 'Invalid csrf token.'); @@ -54,4 +55,27 @@ public function updatePositionsAction(Request $request): Response return new JsonResponse(); } + + /** + * @return mixed + * + * @deprecated This function will be removed in Sylius 2.0, since Symfony 5.4, use explicit input sources instead + * based on Symfony\Component\HttpFoundation\Request::get + */ + private function getParameterFromRequest(Request $request, string $key) + { + if ($request !== $result = $request->attributes->get($key, $request)) { + return $result; + } + + if ($request->query->has($key)) { + return $request->query->all()[$key]; + } + + if ($request->request->has($key)) { + return $request->request->all()[$key]; + } + + return null; + } } diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml index ad56e78531e..58494482a3d 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml @@ -243,5 +243,7 @@ + + diff --git a/src/Sylius/Bundle/CoreBundle/Security/UserImpersonator.php b/src/Sylius/Bundle/CoreBundle/Security/UserImpersonator.php index f5906f18101..9fcce049727 100644 --- a/src/Sylius/Bundle/CoreBundle/Security/UserImpersonator.php +++ b/src/Sylius/Bundle/CoreBundle/Security/UserImpersonator.php @@ -40,12 +40,22 @@ public function __construct(SessionInterface $session, string $firewallContextNa public function impersonate(UserInterface $user): void { - $token = new UsernamePasswordToken( - $user, - $user->getPassword(), - $this->firewallContextName, - array_map(/** @param object|string $role */ static function ($role): string { return (string) $role; }, $user->getRoles()) - ); + /** @deprecated parameter credential was deprecated in Symfony 5.4, so in Sylius 1.11 too, in Sylius 2.0 providing 4 arguments will be prohibited. */ + if (3 === (new \ReflectionClass(UsernamePasswordToken::class))->getConstructor()->getNumberOfParameters()) { + $token = new UsernamePasswordToken( + $user, + $this->firewallContextName, + array_map(/** @param object|string $role */ static function ($role): string { return (string) $role; }, $user->getRoles()) + ); + } else { + $token = new UsernamePasswordToken( + $user, + $user->getPassword(), + $this->firewallContextName, + array_map(/** @param object|string $role */ static function ($role): string { return (string) $role; }, $user->getRoles()) + ); + } + $this->session->set($this->sessionTokenParameter, serialize($token)); $this->session->save(); diff --git a/src/Sylius/Bundle/CoreBundle/composer.json b/src/Sylius/Bundle/CoreBundle/composer.json index 02c068c7fbe..d17064abb1f 100644 --- a/src/Sylius/Bundle/CoreBundle/composer.json +++ b/src/Sylius/Bundle/CoreBundle/composer.json @@ -77,7 +77,7 @@ "matthiasnoback/symfony-dependency-injection-test": "^4.2", "phpspec/phpspec": "^7.0", "phpunit/phpunit": "^8.5", - "symfony/dependency-injection": "^4.4 || ^5.2" + "symfony/dependency-injection": "^4.4 || ^5.4" }, "conflict": { "symfony/doctrine-bridge": "4.4.20 || 5.2.4 || 5.2.5" diff --git a/src/Sylius/Bundle/CurrencyBundle/composer.json b/src/Sylius/Bundle/CurrencyBundle/composer.json index 73a3e5cb21c..10d297b7c3a 100644 --- a/src/Sylius/Bundle/CurrencyBundle/composer.json +++ b/src/Sylius/Bundle/CurrencyBundle/composer.json @@ -30,7 +30,7 @@ "sylius/resource-bundle": "^1.7", "symfony/framework-bundle": "^4.4 || ^5.2", "symfony/intl": "^4.4 || ^5.2", - "symfony/templating": "^4.4 || ^5.2" + "symfony/templating": "^4.4 || ^5.4" }, "conflict": { "twig/twig": "^1.0" diff --git a/src/Sylius/Bundle/CustomerBundle/composer.json b/src/Sylius/Bundle/CustomerBundle/composer.json index b59bce286e9..ef25c628862 100644 --- a/src/Sylius/Bundle/CustomerBundle/composer.json +++ b/src/Sylius/Bundle/CustomerBundle/composer.json @@ -52,7 +52,7 @@ "polishsymfonycommunity/symfony-mocker-container": "^1.0", "symfony/browser-kit": "^4.4 || ^5.2", "symfony/dependency-injection": "^4.4 || ^5.2", - "symfony/form": "^4.4 || ^5.2" + "symfony/form": "^4.4 || ^5.4" }, "config": { "bin-dir": "bin" diff --git a/src/Sylius/Bundle/InventoryBundle/composer.json b/src/Sylius/Bundle/InventoryBundle/composer.json index d9855758723..d65c6eeace0 100644 --- a/src/Sylius/Bundle/InventoryBundle/composer.json +++ b/src/Sylius/Bundle/InventoryBundle/composer.json @@ -31,7 +31,7 @@ "sylius/resource-bundle": "^1.7", "symfony/framework-bundle": "^4.4 || ^5.2", "symfony/templating": "^4.4 || ^5.2", - "symfony/validator": "^4.4 || ^5.2" + "symfony/validator": "^4.4 || ^5.4" }, "conflict": { "twig/twig": "^1.0" diff --git a/src/Sylius/Bundle/LocaleBundle/composer.json b/src/Sylius/Bundle/LocaleBundle/composer.json index f4a172a5a54..4ce406747b5 100644 --- a/src/Sylius/Bundle/LocaleBundle/composer.json +++ b/src/Sylius/Bundle/LocaleBundle/composer.json @@ -30,7 +30,7 @@ "sylius/locale": "^1.6", "sylius/resource-bundle": "^1.7", "symfony/framework-bundle": "^4.4 || ^5.2", - "symfony/templating": "^4.4 || ^5.2" + "symfony/templating": "^4.4 || ^5.4" }, "conflict": { "twig/twig": "^1.0" diff --git a/src/Sylius/Bundle/OrderBundle/Controller/OrderController.php b/src/Sylius/Bundle/OrderBundle/Controller/OrderController.php index 81ced8533e3..3cc77ed3874 100644 --- a/src/Sylius/Bundle/OrderBundle/Controller/OrderController.php +++ b/src/Sylius/Bundle/OrderBundle/Controller/OrderController.php @@ -127,6 +127,9 @@ public function saveAction(Request $request): Response ); } + /** + * @psalm-suppress DeprecatedMethod + */ public function clearAction(Request $request): Response { $configuration = $this->requestConfigurationFactory->create($this->metadata, $request); @@ -134,7 +137,7 @@ public function clearAction(Request $request): Response $this->isGrantedOr403($configuration, ResourceActions::DELETE); $resource = $this->getCurrentCart(); - if ($configuration->isCsrfProtectionEnabled() && !$this->isCsrfTokenValid((string) $resource->getId(), $request->get('_csrf_token'))) { + if ($configuration->isCsrfProtectionEnabled() && !$this->isCsrfTokenValid((string) $resource->getId(), $this->getParameterFromRequest($request, '_csrf_token'))) { throw new HttpException(Response::HTTP_FORBIDDEN, 'Invalid csrf token.'); } @@ -194,4 +197,27 @@ protected function getEventDispatcher(): EventDispatcherInterface { return $this->container->get('event_dispatcher'); } + + /** + * @return mixed + * + * @deprecated This function will be removed in Sylius 2.0, since Symfony 5.4, use explicit input sources instead + * based on Symfony\Component\HttpFoundation\Request::get + */ + private function getParameterFromRequest(Request $request, string $key) + { + if ($request !== $result = $request->attributes->get($key, $request)) { + return $result; + } + + if ($request->query->has($key)) { + return $request->query->all()[$key]; + } + + if ($request->request->has($key)) { + return $request->request->all()[$key]; + } + + return null; + } } diff --git a/src/Sylius/Bundle/OrderBundle/composer.json b/src/Sylius/Bundle/OrderBundle/composer.json index 0f9101dd476..65aed92a7e2 100644 --- a/src/Sylius/Bundle/OrderBundle/composer.json +++ b/src/Sylius/Bundle/OrderBundle/composer.json @@ -34,7 +34,7 @@ "sylius/order": "^1.6", "sylius/resource-bundle": "^1.7", "symfony/framework-bundle": "^4.4 || ^5.2", - "symfony/templating": "^4.4 || ^5.2" + "symfony/templating": "^4.4 || ^5.4" }, "conflict": { "twig/twig": "^1.0 || ^3.0" @@ -46,7 +46,7 @@ "phpunit/phpunit": "^8.5", "symfony/browser-kit": "^4.4 || ^5.2", "symfony/form": "^4.4 || ^5.2", - "symfony/validator": "^4.4 || ^5.2" + "symfony/validator": "^4.4 || ^5.4" }, "config": { "bin-dir": "bin" diff --git a/src/Sylius/Bundle/PaymentBundle/composer.json b/src/Sylius/Bundle/PaymentBundle/composer.json index 5230ca12aa2..7d5b37deaf4 100644 --- a/src/Sylius/Bundle/PaymentBundle/composer.json +++ b/src/Sylius/Bundle/PaymentBundle/composer.json @@ -29,7 +29,7 @@ "php": "^7.4 || ^8.0", "sylius/payment": "^1.6", "sylius/resource-bundle": "^1.7", - "symfony/framework-bundle": "^4.4 || ^5.2" + "symfony/framework-bundle": "^4.4 || ^5.4" }, "conflict": { "twig/twig": "^3.0" @@ -42,7 +42,7 @@ "polishsymfonycommunity/symfony-mocker-container": "^1.0", "sylius/locale-bundle": "^1.6", "symfony/browser-kit": "^4.4 || ^5.2", - "symfony/dependency-injection": "^4.4 || ^5.2" + "symfony/dependency-injection": "^4.4 || ^5.4" }, "config": { "bin-dir": "bin" diff --git a/src/Sylius/Bundle/PayumBundle/composer.json b/src/Sylius/Bundle/PayumBundle/composer.json index ddee02e4acf..5ff41991324 100644 --- a/src/Sylius/Bundle/PayumBundle/composer.json +++ b/src/Sylius/Bundle/PayumBundle/composer.json @@ -40,7 +40,7 @@ }, "require-dev": { "phpspec/phpspec": "^7.0", - "symfony/dependency-injection": "^4.4 || ^5.2" + "symfony/dependency-injection": "^4.4 || ^5.4" }, "config": { "bin-dir": "bin" diff --git a/src/Sylius/Bundle/ProductBundle/Controller/ProductSlugController.php b/src/Sylius/Bundle/ProductBundle/Controller/ProductSlugController.php index 355557b9e5c..9403b53754c 100644 --- a/src/Sylius/Bundle/ProductBundle/Controller/ProductSlugController.php +++ b/src/Sylius/Bundle/ProductBundle/Controller/ProductSlugController.php @@ -13,6 +13,7 @@ namespace Sylius\Bundle\ProductBundle\Controller; +use Sylius\Component\Product\Generator\SlugGeneratorInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -20,10 +21,30 @@ class ProductSlugController extends AbstractController { + private ?SlugGeneratorInterface $slugGenerator; + + public function __construct(?SlugGeneratorInterface $slugGenerator = null) + { + $this->slugGenerator = $slugGenerator; + + if ($this->slugGenerator === null) { + @trigger_error(sprintf('Not passing a $slugGenerator to %s constructor is deprecated since Sylius 1.11 and will be prohibited in Sylius 2.0.', self::class), \E_USER_DEPRECATED); + } + } + + /** + * @psalm-suppress DeprecatedMethod + */ public function generateAction(Request $request): Response { $name = $request->query->get('name'); + if ($this->slugGenerator !== null) { + return new JsonResponse([ + 'slug' => $this->slugGenerator->generate((string) $name), + ]); + } + return new JsonResponse([ 'slug' => $this->get('sylius.generator.slug')->generate($name), ]); diff --git a/src/Sylius/Bundle/ProductBundle/Resources/config/services.xml b/src/Sylius/Bundle/ProductBundle/Resources/config/services.xml index 7738691542c..b6ea78c47d3 100644 --- a/src/Sylius/Bundle/ProductBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/ProductBundle/Resources/config/services.xml @@ -20,6 +20,7 @@ + diff --git a/src/Sylius/Bundle/ProductBundle/composer.json b/src/Sylius/Bundle/ProductBundle/composer.json index 7ded48b857f..88e93bec7c7 100644 --- a/src/Sylius/Bundle/ProductBundle/composer.json +++ b/src/Sylius/Bundle/ProductBundle/composer.json @@ -32,7 +32,7 @@ "sylius/locale-bundle": "^1.6", "sylius/product": "^1.6", "sylius/resource-bundle": "^1.7", - "symfony/framework-bundle": "^4.4 || ^5.2" + "symfony/framework-bundle": "^4.4 || ^5.4" }, "require-dev": { "doctrine/orm": "^2.7", @@ -42,7 +42,7 @@ "symfony/browser-kit": "^4.4 || ^5.2", "symfony/dependency-injection": "^4.4 || ^5.2", "symfony/form": "^4.4 || ^5.2", - "symfony/validator": "^4.4 || ^5.2" + "symfony/validator": "^4.4 || ^5.4" }, "config": { "bin-dir": "bin" diff --git a/src/Sylius/Bundle/PromotionBundle/composer.json b/src/Sylius/Bundle/PromotionBundle/composer.json index 07c53e73bfb..e309ed0a328 100644 --- a/src/Sylius/Bundle/PromotionBundle/composer.json +++ b/src/Sylius/Bundle/PromotionBundle/composer.json @@ -33,7 +33,7 @@ "sylius/promotion": "^1.6", "sylius/registry": "^1.5", "sylius/resource-bundle": "^1.7", - "symfony/framework-bundle": "^4.4 || ^5.2" + "symfony/framework-bundle": "^4.4 || ^5.4" }, "conflict": { "twig/twig": "^3.0" @@ -47,7 +47,7 @@ "symfony/browser-kit": "^4.4 || ^5.2", "symfony/dependency-injection": "^4.4 || ^5.2", "symfony/form": "^4.4 || ^5.2", - "symfony/validator": "^4.4 || ^5.2" + "symfony/validator": "^4.4 || ^5.4" }, "config": { "bin-dir": "bin" diff --git a/src/Sylius/Bundle/ReviewBundle/composer.json b/src/Sylius/Bundle/ReviewBundle/composer.json index f3ba2311ff7..176da87aeae 100644 --- a/src/Sylius/Bundle/ReviewBundle/composer.json +++ b/src/Sylius/Bundle/ReviewBundle/composer.json @@ -44,7 +44,7 @@ "sylius/resource-bundle": "^1.7", "sylius/review": "^1.6", "sylius/user-bundle": "^1.6", - "symfony/framework-bundle": "^4.4 || ^5.2" + "symfony/framework-bundle": "^4.4 || ^5.4" }, "conflict": { "twig/twig": "^3.0" diff --git a/src/Sylius/Bundle/ShippingBundle/composer.json b/src/Sylius/Bundle/ShippingBundle/composer.json index e41cd1e7864..5cf6ad964c1 100644 --- a/src/Sylius/Bundle/ShippingBundle/composer.json +++ b/src/Sylius/Bundle/ShippingBundle/composer.json @@ -33,7 +33,7 @@ "sylius/money-bundle": "^1.6", "sylius/resource-bundle": "^1.7", "sylius/shipping": "^1.6", - "symfony/framework-bundle": "^4.4 || ^5.2" + "symfony/framework-bundle": "^4.4 || ^5.4" }, "conflict": { "twig/twig": "^3.0" @@ -47,7 +47,7 @@ "symfony/browser-kit": "^4.4 || ^5.2", "symfony/dependency-injection": "^4.4 || ^5.2", "symfony/form": "^4.4 || ^5.2", - "symfony/validator": "^4.4 || ^5.2" + "symfony/validator": "^4.4 || ^5.4" }, "config": { "bin-dir": "bin" diff --git a/src/Sylius/Bundle/ShopBundle/composer.json b/src/Sylius/Bundle/ShopBundle/composer.json index dfa4a9dc2e1..3e6c86f9436 100644 --- a/src/Sylius/Bundle/ShopBundle/composer.json +++ b/src/Sylius/Bundle/ShopBundle/composer.json @@ -40,7 +40,7 @@ "mockery/mockery": "^1.4", "phpspec/phpspec": "^7.0", "phpunit/phpunit": "^8.5", - "symfony/dependency-injection": "^4.4 || ^5.2" + "symfony/dependency-injection": "^4.4 || ^5.4" }, "config": { "bin-dir": "bin" diff --git a/src/Sylius/Bundle/TaxationBundle/composer.json b/src/Sylius/Bundle/TaxationBundle/composer.json index d268d315195..99e9ab9f5ad 100644 --- a/src/Sylius/Bundle/TaxationBundle/composer.json +++ b/src/Sylius/Bundle/TaxationBundle/composer.json @@ -32,7 +32,7 @@ "sylius/registry": "^1.5", "sylius/resource-bundle": "^1.7", "sylius/taxation": "^1.6", - "symfony/framework-bundle": "^4.4 || ^5.2" + "symfony/framework-bundle": "^4.4 || ^5.4" }, "conflict": { "twig/twig": "^3.0" @@ -45,7 +45,7 @@ "polishsymfonycommunity/symfony-mocker-container": "^1.0", "symfony/browser-kit": "^4.4 || ^5.2", "symfony/dependency-injection": "^4.4 || ^5.2", - "symfony/form": "^4.4 || ^5.2" + "symfony/form": "^4.4 || ^5.4" }, "config": { "bin-dir": "bin" diff --git a/src/Sylius/Bundle/TaxonomyBundle/composer.json b/src/Sylius/Bundle/TaxonomyBundle/composer.json index 1baa305968a..fa6e29fc5ad 100644 --- a/src/Sylius/Bundle/TaxonomyBundle/composer.json +++ b/src/Sylius/Bundle/TaxonomyBundle/composer.json @@ -32,7 +32,7 @@ "stof/doctrine-extensions-bundle": "^1.4", "sylius/resource-bundle": "^1.7", "sylius/taxonomy": "^1.6", - "symfony/framework-bundle": "^4.4 || ^5.2" + "symfony/framework-bundle": "^4.4 || ^5.4" }, "conflict": { "twig/twig": "^3.0" @@ -41,7 +41,7 @@ "doctrine/orm": "^2.7", "phpspec/phpspec": "^7.0", "phpunit/phpunit": "^8.5", - "symfony/dependency-injection": "^4.4 || ^5.2" + "symfony/dependency-injection": "^4.4 || ^5.4" }, "config": { "bin-dir": "bin" diff --git a/src/Sylius/Bundle/UserBundle/Controller/SecurityController.php b/src/Sylius/Bundle/UserBundle/Controller/SecurityController.php index fac2a1174f9..150cfdd1afc 100644 --- a/src/Sylius/Bundle/UserBundle/Controller/SecurityController.php +++ b/src/Sylius/Bundle/UserBundle/Controller/SecurityController.php @@ -15,18 +15,45 @@ use Sylius\Bundle\UserBundle\Form\Type\UserLoginType; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Webmozart\Assert\Assert; class SecurityController extends AbstractController { + private ?AuthenticationUtils $authenticationUtils; + + private ?FormFactoryInterface $formFactory; + + public function __construct(?AuthenticationUtils $authenticationUtils = null, ?FormFactoryInterface $formFactory = null) + { + $this->authenticationUtils = $authenticationUtils; + $this->formFactory = $formFactory; + + if ($this->authenticationUtils === null) { + @trigger_error(sprintf('Not passing a $authenticationUtils to %s constructor is deprecated since Sylius 1.11 and will be prohibited in Sylius 2.0.', self::class), \E_USER_DEPRECATED); + } + + if ($this->formFactory === null) { + @trigger_error(sprintf('Not passing a $formFactory to %s constructor is deprecated since Sylius 1.11 and will be prohibited in Sylius 2.0.', self::class), \E_USER_DEPRECATED); + } + } + /** * Login form action. + * + * @psalm-suppress DeprecatedMethod */ public function loginAction(Request $request): Response { - $authenticationUtils = $this->get('security.authentication_utils'); + if ($this->authenticationUtils !== null) { + $authenticationUtils = $this->authenticationUtils; + } else { + $authenticationUtils = $this->get('security.authentication_utils'); + } + $error = $authenticationUtils->getLastAuthenticationError(); $lastUsername = $authenticationUtils->getLastUsername(); @@ -36,7 +63,12 @@ public function loginAction(Request $request): Response Assert::notNull($template, 'Template is not configured.'); $formType = $options['form'] ?? UserLoginType::class; - $form = $this->get('form.factory')->createNamed('', $formType); + + if ($this->formFactory !== null) { + $form = $this->formFactory->createNamed('', $formType); + } else { + $form = $this->get('form.factory')->createNamed('', $formType); + } return $this->render($template, [ 'form' => $form->createView(), diff --git a/src/Sylius/Bundle/UserBundle/Resources/config/services.xml b/src/Sylius/Bundle/UserBundle/Resources/config/services.xml index 09b04539d3e..6a9c3c4e31f 100644 --- a/src/Sylius/Bundle/UserBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/UserBundle/Resources/config/services.xml @@ -40,6 +40,8 @@ + + diff --git a/src/Sylius/Bundle/UserBundle/Security/UserLogin.php b/src/Sylius/Bundle/UserBundle/Security/UserLogin.php index af8fe52b807..60337c95785 100644 --- a/src/Sylius/Bundle/UserBundle/Security/UserLogin.php +++ b/src/Sylius/Bundle/UserBundle/Security/UserLogin.php @@ -58,6 +58,15 @@ public function login(UserInterface $user, ?string $firewallName = null): void protected function createToken(UserInterface $user, string $firewallName): UsernamePasswordToken { + /** @deprecated parameter credential was deprecated in Symfony 5.4, so in Sylius 1.11 too, in Sylius 2.0 providing 4 arguments will be prohibited. */ + if (3 === (new \ReflectionClass(UsernamePasswordToken::class))->getConstructor()->getNumberOfParameters()) { + return new UsernamePasswordToken( + $user, + $firewallName, + array_map(/** @param object|string $role */ static function ($role): string { return (string) $role; }, $user->getRoles()) + ); + } + return new UsernamePasswordToken( $user, null, diff --git a/src/Sylius/Component/Addressing/composer.json b/src/Sylius/Component/Addressing/composer.json index 636771c5d92..2396ec8c601 100644 --- a/src/Sylius/Component/Addressing/composer.json +++ b/src/Sylius/Component/Addressing/composer.json @@ -29,7 +29,7 @@ "php": "^7.4 || ^8.0", "sylius/registry": "^1.5", "sylius/resource": "^1.7", - "symfony/intl": "^4.4 || ^5.2" + "symfony/intl": "^4.4 || ^5.4" }, "require-dev": { "phpspec/phpspec": "^7.0" diff --git a/src/Sylius/Component/Attribute/composer.json b/src/Sylius/Component/Attribute/composer.json index e10e062bee1..3bba74e4226 100644 --- a/src/Sylius/Component/Attribute/composer.json +++ b/src/Sylius/Component/Attribute/composer.json @@ -29,7 +29,7 @@ "doctrine/collections": "^1.6", "sylius/registry": "^1.5", "sylius/resource": "^1.7", - "symfony/validator": "^4.4 || ^5.2" + "symfony/validator": "^4.4 || ^5.4" }, "require-dev": { "phpspec/phpspec": "^7.0" diff --git a/src/Sylius/Component/Core/composer.json b/src/Sylius/Component/Core/composer.json index 0cd4068b02b..dc23d7c04a0 100644 --- a/src/Sylius/Component/Core/composer.json +++ b/src/Sylius/Component/Core/composer.json @@ -56,7 +56,7 @@ }, "require-dev": { "phpspec/phpspec": "^7.0", - "symfony/property-access": "^4.4 || ^5.2" + "symfony/property-access": "^4.4 || ^5.4" }, "config": { "bin-dir": "bin" diff --git a/src/Sylius/Component/Shipping/composer.json b/src/Sylius/Component/Shipping/composer.json index 3853e4ae6d7..60c95390f38 100644 --- a/src/Sylius/Component/Shipping/composer.json +++ b/src/Sylius/Component/Shipping/composer.json @@ -31,7 +31,7 @@ "php": "^7.4 || ^8.0", "sylius/registry": "^1.5", "sylius/resource": "^1.7", - "symfony/options-resolver": "^4.4 || ^5.2" + "symfony/options-resolver": "^4.4 || ^5.4" }, "require-dev": { "phpspec/phpspec": "^7.0" diff --git a/src/Sylius/Component/User/composer.json b/src/Sylius/Component/User/composer.json index 802bc38103c..6bf4a3f03bf 100644 --- a/src/Sylius/Component/User/composer.json +++ b/src/Sylius/Component/User/composer.json @@ -38,7 +38,7 @@ "sylius-labs/polyfill-symfony-security": "^1.0", "sylius/resource": "^1.7", "symfony/polyfill-mbstring": "^1.17", - "symfony/security-core": "^4.4 || ^5.2" + "symfony/security-core": "^4.4 || ^5.4" }, "require-dev": { "phpspec/phpspec": "^7.0" diff --git a/tests/Controller/AdminProductAjaxTest.php b/tests/Controller/AdminProductAjaxTest.php index 5aa8a62e1fc..3e7139b39b6 100644 --- a/tests/Controller/AdminProductAjaxTest.php +++ b/tests/Controller/AdminProductAjaxTest.php @@ -65,7 +65,14 @@ private function authenticateAdminUser(): void $session = self::$container->get('session'); $firewallName = 'admin'; $firewallContext = 'admin'; - $token = new UsernamePasswordToken($user, null, $firewallName, $user->getRoles()); + + /** @deprecated parameter credential was deprecated in Symfony 5.4, so in Sylius 1.11 too, in Sylius 2.0 providing 4 arguments will be prohibited. */ + if (3 === (new \ReflectionClass(UsernamePasswordToken::class))->getConstructor()->getNumberOfParameters()) { + $token = new UsernamePasswordToken($user, $firewallName, $user->getRoles()); + } else { + $token = new UsernamePasswordToken($user, null, $firewallName, $user->getRoles()); + } + $session->set(sprintf('_security_%s', $firewallContext), serialize($token)); $session->save();