Skip to content

Commit

Permalink
Drop Symfony 4.4 and Twig 2 (#1632)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 authored Apr 21, 2023
1 parent ecb9799 commit 8098ab1
Show file tree
Hide file tree
Showing 48 changed files with 187 additions and 535 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ jobs:
dependencies: lowest
allowed-to-fail: false
variant: normal
- php-version: '8.2'
dependencies: highest
allowed-to-fail: false
symfony-require: 4.4.*
variant: symfony/symfony:"4.4.*"
- php-version: '8.2'
dependencies: highest
allowed-to-fail: false
Expand Down
48 changes: 24 additions & 24 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@
"sonata-project/doctrine-extensions": "^1.13 || ^2.0",
"sonata-project/form-extensions": "^1.4",
"sonata-project/twig-extensions": "^1.3 || ^2.0",
"symfony/config": "^4.4.11 || ^5.4 || ^6.2",
"symfony/console": "^4.4 || ^5.4 || ^6.2",
"symfony/dependency-injection": "^4.4 || ^5.4 || ^6.2",
"symfony/event-dispatcher": "^4.4 || ^5.4 || ^6.2",
"symfony/form": "^4.4.20 || ^5.4 || ^6.2",
"symfony/framework-bundle": "^4.4 || ^5.4 || ^6.2",
"symfony/http-foundation": "^4.4 || ^5.4 || ^6.2",
"symfony/http-kernel": "^4.4 || ^5.4 || ^6.2",
"symfony/mailer": "^4.4 || ^5.4 || ^6.2",
"symfony/mime": "^4.4.10 || ^5.4 || ^6.2",
"symfony/options-resolver": "^4.4 || ^5.4 || ^6.2",
"symfony/routing": "^4.4 || ^5.4 || ^6.2",
"symfony/config": "^5.4 || ^6.2",
"symfony/console": "^5.4 || ^6.2",
"symfony/dependency-injection": "^5.4 || ^6.2",
"symfony/event-dispatcher": "^5.4 || ^6.2",
"symfony/form": "^5.4 || ^6.2",
"symfony/framework-bundle": "^5.4 || ^6.2",
"symfony/http-foundation": "^5.4 || ^6.2",
"symfony/http-kernel": "^5.4 || ^6.2",
"symfony/mailer": "^5.4 || ^6.2",
"symfony/mime": "^5.4 || ^6.2",
"symfony/options-resolver": "^5.4 || ^6.2",
"symfony/routing": "^5.4 || ^6.2",
"symfony/security-acl": "^3.0",
"symfony/security-core": "^4.4.23 || ^5.4 || ^6.2",
"symfony/security-csrf": "^4.4 || ^5.4 || ^6.2",
"symfony/translation": "^4.4 || ^5.4 || ^6.2",
"symfony/translation-contracts": "^1.1 || ^2.5 || ^3.0",
"symfony/validator": "^4.4 || ^5.4 || ^6.2",
"twig/twig": "^2.14 || ^3.0"
"symfony/security-core": "^5.4 || ^6.2",
"symfony/security-csrf": "^5.4 || ^6.2",
"symfony/translation": "^5.4 || ^6.2",
"symfony/translation-contracts": "^2.5 || ^3.0",
"symfony/validator": "^5.4 || ^6.2",
"twig/twig": "^3.0"
},
"require-dev": {
"dama/doctrine-test-bundle": "^7.0",
Expand All @@ -63,17 +63,17 @@
"phpstan/phpstan-symfony": "^1.0",
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.18",
"psalm/plugin-symfony": "^4.0 || ^5.0",
"psalm/plugin-symfony": "^5.0",
"rector/rector": "^0.15",
"sonata-project/admin-bundle": "^4.20",
"sonata-project/block-bundle": "^4.11",
"sonata-project/doctrine-orm-admin-bundle": "^4.0",
"symfony/browser-kit": "^4.4 || ^5.4 || ^6.2",
"symfony/console": "^4.4 || ^5.4 || ^6.2",
"symfony/filesystem": "^4.4 || ^5.4 || ^6.2",
"symfony/intl": "^4.4 || ^5.4 || ^6.2",
"symfony/browser-kit": "^5.4 || ^6.2",
"symfony/console": "^5.4 || ^6.2",
"symfony/filesystem": "^5.4 || ^6.2",
"symfony/intl": "^5.4 || ^6.2",
"symfony/phpunit-bridge": "^6.2",
"vimeo/psalm": "^4.9.2 || ^5.0"
"vimeo/psalm": "^5.0"
},
"conflict": {
"sonata-project/admin-bundle": "<4.20",
Expand Down
13 changes: 0 additions & 13 deletions psalm-baseline.xml

This file was deleted.

2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="2" findUnusedPsalmSuppress="true" findUnusedBaselineEntry="true" findUnusedCode="false" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" errorBaseline="psalm-baseline.xml">
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="2" findUnusedPsalmSuppress="true" findUnusedBaselineEntry="true" findUnusedCode="false" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
Expand Down
8 changes: 0 additions & 8 deletions src/Command/ActivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,14 @@
#[AsCommand(name: 'sonata:user:activate', description: 'Activate a user')]
final class ActivateUserCommand extends Command
{
// TODO: Remove static properties when support for Symfony < 5.4 is dropped.
protected static $defaultName = 'sonata:user:activate';
protected static $defaultDescription = 'Activate a user';

public function __construct(private UserManagerInterface $userManager)
{
parent::__construct();
}

protected function configure(): void
{
\assert(null !== static::$defaultDescription);

$this
// TODO: Remove setDescription when support for Symfony < 5.4 is dropped.
->setDescription(static::$defaultDescription)
->setDefinition([
new InputArgument('username', InputArgument::REQUIRED, 'The username'),
])
Expand Down
8 changes: 0 additions & 8 deletions src/Command/ChangePasswordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,14 @@
#[AsCommand(name: 'sonata:user:change-password', description: 'Change the password of a user')]
final class ChangePasswordCommand extends Command
{
// TODO: Remove static properties when support for Symfony < 5.4 is dropped.
protected static $defaultName = 'sonata:user:change-password';
protected static $defaultDescription = 'Change the password of a user';

public function __construct(private UserManagerInterface $userManager)
{
parent::__construct();
}

protected function configure(): void
{
\assert(null !== static::$defaultDescription);

$this
// TODO: Remove setDescription when support for Symfony < 5.4 is dropped.
->setDescription(static::$defaultDescription)
->setDefinition([
new InputArgument('username', InputArgument::REQUIRED, 'The username'),
new InputArgument('password', InputArgument::REQUIRED, 'The password'),
Expand Down
8 changes: 0 additions & 8 deletions src/Command/CreateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,14 @@
#[AsCommand(name: 'sonata:user:create', description: 'Create a user')]
final class CreateUserCommand extends Command
{
// TODO: Remove static properties when support for Symfony < 5.4 is dropped.
protected static $defaultName = 'sonata:user:create';
protected static $defaultDescription = 'Create a user';

public function __construct(private UserManagerInterface $userManager)
{
parent::__construct();
}

protected function configure(): void
{
\assert(null !== static::$defaultDescription);

$this
// TODO: Remove setDescription when support for Symfony < 5.4 is dropped.
->setDescription(static::$defaultDescription)
->setDefinition([
new InputArgument('username', InputArgument::REQUIRED, 'The username'),
new InputArgument('email', InputArgument::REQUIRED, 'The email'),
Expand Down
8 changes: 0 additions & 8 deletions src/Command/DeactivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,14 @@
#[AsCommand(name: 'sonata:user:deactivate', description: 'Deactivate a user')]
final class DeactivateUserCommand extends Command
{
// TODO: Remove static properties when support for Symfony < 5.4 is dropped.
protected static $defaultName = 'sonata:user:deactivate';
protected static $defaultDescription = 'Deactivate a user';

public function __construct(private UserManagerInterface $userManager)
{
parent::__construct();
}

protected function configure(): void
{
\assert(null !== static::$defaultDescription);

$this
// TODO: Remove setDescription when support for Symfony < 5.4 is dropped.
->setDescription(static::$defaultDescription)
->setDefinition([
new InputArgument('username', InputArgument::REQUIRED, 'The username'),
])
Expand Down
8 changes: 0 additions & 8 deletions src/Command/DemoteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,14 @@
#[AsCommand(name: 'sonata:user:demote', description: 'Demotes a user by removing a role')]
final class DemoteUserCommand extends Command
{
// TODO: Remove static properties when support for Symfony < 5.4 is dropped.
protected static $defaultName = 'sonata:user:demote';
protected static $defaultDescription = 'Demotes a user by removing a role';

public function __construct(private UserManagerInterface $userManager)
{
parent::__construct();
}

protected function configure(): void
{
\assert(null !== static::$defaultDescription);

$this
// TODO: Remove setDescription when support for Symfony < 5.4 is dropped.
->setDescription(static::$defaultDescription)
->setDefinition([
new InputArgument('username', InputArgument::REQUIRED, 'The username'),
new InputArgument('role', InputArgument::OPTIONAL, 'The role'),
Expand Down
8 changes: 0 additions & 8 deletions src/Command/PromoteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,14 @@
#[AsCommand(name: 'sonata:user:promote', description: 'Promotes a user by adding a role')]
final class PromoteUserCommand extends Command
{
// TODO: Remove static properties when support for Symfony < 5.4 is dropped.
protected static $defaultName = 'sonata:user:promote';
protected static $defaultDescription = 'Promotes a user by adding a role';

public function __construct(private UserManagerInterface $userManager)
{
parent::__construct();
}

protected function configure(): void
{
\assert(null !== static::$defaultDescription);

$this
// TODO: Remove setDescription when support for Symfony < 5.4 is dropped.
->setDescription(static::$defaultDescription)
->setDefinition([
new InputArgument('username', InputArgument::REQUIRED, 'The username'),
new InputArgument('role', InputArgument::OPTIONAL, 'The role'),
Expand Down
8 changes: 3 additions & 5 deletions src/DependencyInjection/SonataUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ public function load(array $configs, ContainerBuilder $container): void
$this->configureResetting($config['resetting'], $container);
}

if ($this->isConfigEnabled($container, $config['impersonating'])) {
$this->configureImpersonation($config['impersonating'], $container);
}
$this->configureImpersonation($config['impersonating'], $container);
}

/**
Expand Down Expand Up @@ -186,7 +184,7 @@ private function configureImpersonation(array $config, ContainerBuilder $contain
{
$container->getDefinition('sonata.user.twig.global')
->replaceArgument(2, $config['enabled'])
->replaceArgument(3, $config['route'])
->replaceArgument(4, $config['parameters']);
->replaceArgument(3, $config['route'] ?? '')
->replaceArgument(4, $config['parameters'] ?? []);
}
}
18 changes: 2 additions & 16 deletions src/Document/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Sonata\UserBundle\Model\UserManagerInterface;
use Sonata\UserBundle\Util\CanonicalFieldsUpdaterInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;

/**
* @author Hugo Briand <[email protected]>
Expand All @@ -29,25 +28,17 @@
final class UserManager extends BaseDocumentManager implements UserManagerInterface
{
/**
* TODO: Simplify this once support for Symfony 4.4 is dropped.
*
* @param UserPasswordEncoderInterface|UserPasswordHasherInterface $userPasswordHasher
*
* @phpstan-param class-string<UserInterface> $class
*/
public function __construct(
string $class,
ManagerRegistry $registry,
private CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater,
// @phpstan-ignore-next-line
private object $userPasswordHasher
private UserPasswordHasherInterface $userPasswordHasher
) {
parent::__construct($class, $registry);
}

/**
* @psalm-suppress UndefinedDocblockClass
*/
public function updatePassword(UserInterface $user): void
{
$plainPassword = $user->getPlainPassword();
Expand All @@ -56,12 +47,7 @@ public function updatePassword(UserInterface $user): void
return;
}

if ($this->userPasswordHasher instanceof UserPasswordHasherInterface) {
$password = $this->userPasswordHasher->hashPassword($user, $plainPassword);
} else {
// @phpstan-ignore-next-line
$password = $this->userPasswordHasher->encodePassword($user, $plainPassword);
}
$password = $this->userPasswordHasher->hashPassword($user, $plainPassword);

$user->setPassword($password);
$user->eraseCredentials();
Expand Down
18 changes: 2 additions & 16 deletions src/Entity/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Sonata\UserBundle\Model\UserManagerInterface;
use Sonata\UserBundle\Util\CanonicalFieldsUpdaterInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;

/**
* @author Hugo Briand <[email protected]>
Expand All @@ -29,25 +28,17 @@
final class UserManager extends BaseEntityManager implements UserManagerInterface
{
/**
* TODO: Simplify this once support for Symfony 4.4 is dropped.
*
* @param UserPasswordEncoderInterface|UserPasswordHasherInterface $userPasswordHasher
*
* @phpstan-param class-string<UserInterface> $class
*/
public function __construct(
string $class,
ManagerRegistry $registry,
private CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater,
// @phpstan-ignore-next-line
private object $userPasswordHasher
private UserPasswordHasherInterface $userPasswordHasher
) {
parent::__construct($class, $registry);
}

/**
* @psalm-suppress UndefinedDocblockClass
*/
public function updatePassword(UserInterface $user): void
{
$plainPassword = $user->getPlainPassword();
Expand All @@ -56,12 +47,7 @@ public function updatePassword(UserInterface $user): void
return;
}

if ($this->userPasswordHasher instanceof UserPasswordHasherInterface) {
$password = $this->userPasswordHasher->hashPassword($user, $plainPassword);
} else {
// @phpstan-ignore-next-line
$password = $this->userPasswordHasher->encodePassword($user, $plainPassword);
}
$password = $this->userPasswordHasher->hashPassword($user, $plainPassword);

$user->setPassword($password);
$user->eraseCredentials();
Expand Down
29 changes: 0 additions & 29 deletions src/Model/BCPasswordAuthenticatedUserInterface.php

This file was deleted.

Loading

0 comments on commit 8098ab1

Please sign in to comment.