Skip to content

Commit

Permalink
feature Sylius#13339 Add Support for Symfony 5.4 (AdamKasp)
Browse files Browse the repository at this point in the history
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

<!--
 - Bug fixes must be submitted against the 1.10 branch
 - Features and deprecations must be submitted against the master branch
 - Make sure that the correct base branch is set

 To be sure you are not breaking any Backward Compatibilities, check the documentation:
 https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->

Commits
-------

28a02a6 Prepare Sylius for support Symfony 5.4
d2c39e4 remove usage of symfony internal method
fef6243 bump symofny verion from 5.4.0-RC1 to 5.4
6339528 update argument in UsernamePasswordToken
2964e0e make workorounds over deprecated method in symofny 5.4
  • Loading branch information
GSadee authored and lchrusciel committed Dec 6, 2021
1 parent 860c3e8 commit b8b7e8d
Show file tree
Hide file tree
Showing 49 changed files with 296 additions and 123 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
-
Expand Down Expand Up @@ -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"]

Expand Down Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<referencedMethod name="Symfony\Component\Security\Core\User\UserInterface::getUsername" /> <!-- deprecated in Symfony 5.3 -->
<referencedMethod name="Symfony\Component\Security\Core\User\UserProviderInterface::loadUserByUsername" /> <!-- deprecated in Symfony 5.3 -->
<referencedMethod name="Faker\Generator::__get"/>
<referencedMethod name="Symfony\Component\Security\Core\Authentication\Token\AbstractToken::isAuthenticated" /> <!-- deprecated in Symfony 5.4 -->
</errorLevel>
</DeprecatedMethod>

Expand Down Expand Up @@ -202,6 +203,7 @@
<referencedFunction name="Symfony\Contracts\EventDispatcher\EventDispatcherInterface::dispatch" />
<referencedFunction name="Symfony\Component\HttpKernel\Config\FileLocator::__construct" />
<referencedFunction name="Symfony\Contracts\EventDispatcher\EventDispatcherInterface::dispatch" />
<referencedFunction name="Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::__construct" /> <!-- removed parameter in Symfony 5.4 -->
</errorLevel>
<errorLevel type="suppress">
<referencedFunction name="Doctrine\ORM\Query\Expr::andX" />
Expand All @@ -225,6 +227,7 @@
<errorLevel type="info">
<referencedFunction name="Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch" />
<referencedFunction name="SyliusLabs\AssociationHydrator\AssociationHydrator::__construct" />
<referencedFunction name="Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::__construct" />
</errorLevel>
</InvalidArgument>

Expand Down
8 changes: 7 additions & 1 deletion src/Sylius/Behat/Service/SecurityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 6 additions & 6 deletions src/Sylius/Bundle/AddressingBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"stof/doctrine-extensions-bundle": "^1.4",
"sylius/addressing": "^1.6",
"sylius/resource-bundle": "^1.7",
"symfony/framework-bundle": "^4.4 || ^5.2",
"symfony/intl": "^4.4 || ^5.2"
"symfony/framework-bundle": "^4.4 || ^5.4",
"symfony/intl": "^4.4 || ^5.4"
},
"conflict": {
"twig/twig": "^1.0 || ^3.0"
Expand All @@ -41,10 +41,10 @@
"phpspec/phpspec": "^7.0",
"phpunit/phpunit": "^8.5",
"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/validator": "^4.4 || ^5.2"
"symfony/browser-kit": "^4.4 || ^5.4",
"symfony/dependency-injection": "^4.4 || ^5.4",
"symfony/form": "^4.4 || ^5.4",
"symfony/validator": "^4.4 || ^5.4"
},
"config": {
"bin-dir": "bin"
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Bundle/AdminBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
"php": "^7.4 || ^8.0",
"sylius/core-bundle": "^1.6",
"sylius/ui-bundle": "^1.6",
"symfony/framework-bundle": "^4.4 || ^5.2",
"symfony/framework-bundle": "^4.4 || ^5.4",
"twig/intl-extra": "^2.12",
"twig/twig": "^2.12"
},
"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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
8 changes: 4 additions & 4 deletions src/Sylius/Bundle/ApiBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
"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",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"nelmio/alice": "^3.8",
"phpspec/phpspec": "^7.0",
"phpunit/phpunit": "^8.5",
"symfony/browser-kit": "^4.4 || ^5.2",
"symfony/debug-bundle": "^4.4 || ^5.2",
"symfony/dotenv": "^4.4 || ^5.2",
"symfony/browser-kit": "^4.4 || ^5.4",
"symfony/debug-bundle": "^4.4 || ^5.4",
"symfony/dotenv": "^4.4 || ^5.4",
"symfony/http-client": "^5.2",
"theofidry/alice-data-fixtures": "^1.4"
},
Expand Down
8 changes: 4 additions & 4 deletions src/Sylius/Bundle/AttributeBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
"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",
"phpspec/phpspec": "^7.0",
"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/browser-kit": "^4.4 || ^5.4",
"symfony/dependency-injection": "^4.4 || ^5.4",
"symfony/form": "^4.4 || ^5.4"
},
"config": {
"bin-dir": "bin"
Expand Down
8 changes: 4 additions & 4 deletions src/Sylius/Bundle/ChannelBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
"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",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"phpspec/phpspec": "^7.0",
"phpunit/phpunit": "^8.5",
"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/browser-kit": "^4.4 || ^5.4",
"symfony/dependency-injection": "^4.4 || ^5.4",
"symfony/form": "^4.4 || ^5.4",
"twig/twig": "^2.12"
},
"config": {
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Bundle/CoreBundle/Command/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
33 changes: 30 additions & 3 deletions src/Sylius/Bundle/CoreBundle/Controller/ProductTaxonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand All @@ -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;
}
}
2 changes: 2 additions & 0 deletions src/Sylius/Bundle/CoreBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,7 @@
<service class="Sylius\Bundle\CoreBundle\Mailer\OrderEmailManager" id="sylius.mailer.order_email_manager">
<argument type="service" id="sylius.email_sender" />
</service>

<service id="security.authentication_manager" alias="security.authentication.manager" />
</services>
</container>
22 changes: 16 additions & 6 deletions src/Sylius/Bundle/CoreBundle/Security/UserImpersonator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
10 changes: 5 additions & 5 deletions src/Sylius/Bundle/CoreBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
"sylius/theme-bundle": "^2.1.1",
"sylius/ui-bundle": "^1.6",
"sylius/user-bundle": "^1.6",
"symfony/framework-bundle": "^4.4 || ^5.2",
"symfony/intl": "^4.4 || ^5.2",
"symfony/messenger": "^4.4 || ^5.2",
"symfony/framework-bundle": "^4.4 || ^5.4",
"symfony/intl": "^4.4 || ^5.4",
"symfony/messenger": "^4.4 || ^5.4",
"symfony/swiftmailer-bundle": "^3.4",
"symfony/templating": "^4.4 || ^5.2",
"symfony/templating": "^4.4 || ^5.4",
"winzou/state-machine-bundle": "^0.5"
},
"require-dev": {
Expand All @@ -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"
Expand Down
Loading

0 comments on commit b8b7e8d

Please sign in to comment.