From 81cce03cca92a69f5c8c7e53334fe21e993e539f Mon Sep 17 00:00:00 2001 From: Vincent Chalamon <407859+vincentchalamon@users.noreply.github.com> Date: Tue, 14 Jan 2025 17:11:29 +0100 Subject: [PATCH] chore: remove deprecations Remove support of API Platform 3.x Replace api-platform/core dependency by api-platform/openapi Remove support of Symfony 5.x --- composer.json | 38 +-- config/services.xml | 2 - .../OpenApi/AbstractOpenApiFactory.php | 220 ------------------ .../ApiPlatform/OpenApi/OpenApiFactory.php | 217 +++++++++++++++-- src/DependencyInjection/BCExtensionTrait.php | 17 -- src/Exception/MissingFieldHttpException.php | 3 +- src/Manager/ForgotPasswordManager.php | 20 +- src/Manager/PasswordTokenManager.php | 28 +-- 8 files changed, 221 insertions(+), 324 deletions(-) delete mode 100644 src/Bridge/ApiPlatform/OpenApi/AbstractOpenApiFactory.php diff --git a/composer.json b/composer.json index e2206f1..cf548b8 100644 --- a/composer.json +++ b/composer.json @@ -17,16 +17,16 @@ ], "require": { "php": ">=8.1", - "symfony/config": "^5.1 || ^6.0 || ^7.0", - "symfony/dependency-injection": "^5.1 || ^6.0 || ^7.0", - "symfony/event-dispatcher": "^5.1 || ^6.0 || ^7.0", - "symfony/http-foundation": "^5.1 || ^6.0 || ^7.0", - "symfony/http-kernel": "^5.1.5 || ^6.0 || ^7.0", - "symfony/serializer": "^5.1 || ^6.0 || ^7.0" + "symfony/config": "^6.4 || ^7.0", + "symfony/dependency-injection": "^6.4 || ^7.0", + "symfony/event-dispatcher": "^6.4 || ^7.0", + "symfony/http-foundation": "^6.4 || ^7.0", + "symfony/http-kernel": "^6.4 || ^7.0", + "symfony/serializer": "^6.4 || ^7.0" }, "require-dev": { "ext-json": "*", - "api-platform/core": "^3.0 || ^4.0", + "api-platform/openapi": "^4.0", "behat/behat": "^3.1", "dg/bypass-finals": "^1.1", "doctrine/data-fixtures": "^1.2", @@ -37,22 +37,22 @@ "laminas/laminas-code": "^3.4 || ^4.0", "ocramius/proxy-manager": "^2.0.4", "sebastian/comparator": "^3.0", - "symfony/asset": "^5.1 || ^6.0 || ^7.0", - "symfony/browser-kit": "^5.1 || ^6.0 || ^7.0", - "symfony/framework-bundle": "^5.1 || ^6.0 || ^7.0", - "symfony/mailer": "^5.1 || ^6.0 || ^7.0", - "symfony/phpunit-bridge": "^5.1 || ^6.0 || ^7.0", - "symfony/property-access": "^5.1 || ^6.0 || ^7.0", - "symfony/security-bundle": "^5.1 || ^6.0 || ^7.0", - "symfony/stopwatch": "^5.1 || ^6.0 || ^7.0", - "symfony/templating": "^5.1 || ^6.0 || ^7.0", - "symfony/twig-bundle": "^5.1 || ^6.0 || ^7.0", - "symfony/var-dumper": "^5.1 || ^6.0 || ^7.0" + "symfony/asset": "^6.4 || ^7.0", + "symfony/browser-kit": "^6.4 || ^7.0", + "symfony/framework-bundle": "^6.4 || ^7.0", + "symfony/mailer": "^6.4 || ^7.0", + "symfony/phpunit-bridge": "^6.4 || ^7.0", + "symfony/property-access": "^6.4 || ^7.0", + "symfony/security-bundle": "^6.4 || ^7.0", + "symfony/stopwatch": "^6.4 || ^7.0", + "symfony/templating": "^6.4 || ^7.0", + "symfony/twig-bundle": "^6.4 || ^7.0", + "symfony/var-dumper": "^6.4 || ^7.0" }, "suggest": { "doctrine/doctrine-bundle": "To connect with Doctrine in Symfony project", "doctrine/orm": "To connect with Doctrine", - "api-platform/core": "To connect with API Platform" + "api-platform/openapi": "To connect with API Platform" }, "autoload": { "psr-4": { diff --git a/config/services.xml b/config/services.xml index e6f23dd..b00f9e8 100644 --- a/config/services.xml +++ b/config/services.xml @@ -25,11 +25,9 @@ - - diff --git a/src/Bridge/ApiPlatform/OpenApi/AbstractOpenApiFactory.php b/src/Bridge/ApiPlatform/OpenApi/AbstractOpenApiFactory.php deleted file mode 100644 index 15d130f..0000000 --- a/src/Bridge/ApiPlatform/OpenApi/AbstractOpenApiFactory.php +++ /dev/null @@ -1,220 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace CoopTilleuls\ForgotPasswordBundle\Bridge\ApiPlatform\OpenApi; - -use ApiPlatform\Core\OpenApi\Factory\OpenApiFactoryInterface as LegacyOpenApiFactoryInterface; -use ApiPlatform\Core\OpenApi\Model\Operation as LegacyOperation; -use ApiPlatform\Core\OpenApi\Model\PathItem as LegacyPathItem; -use ApiPlatform\Core\OpenApi\Model\RequestBody as LegacyRequestBody; -use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface; -use ApiPlatform\OpenApi\Model\Operation; -use ApiPlatform\OpenApi\Model\PathItem; -use ApiPlatform\OpenApi\Model\RequestBody; -use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderChainInterface; -use Symfony\Component\Routing\RouterInterface; - -/** - * @author Vincent CHALAMON - */ -abstract class AbstractOpenApiFactory -{ - public function __construct(protected readonly LegacyOpenApiFactoryInterface|OpenApiFactoryInterface $decorated, protected readonly RouterInterface $router, protected readonly ProviderChainInterface $providerChain) - { - } - - public function __invoke(array $context = []) - { - $routes = $this->router->getRouteCollection(); - $openApi = ($this->decorated)($context); - $schemas = $openApi->getComponents()->getSchemas(); - $paths = $openApi->getPaths(); - - $resetProperties = []; - $requestProperties = []; - foreach ($this->providerChain->all() as $provider) { - $userPasswordField = $provider->getUserPasswordField(); - if (!\array_key_exists($userPasswordField, $resetProperties)) { - $resetProperties[$userPasswordField] = [ - 'type' => 'object', - 'required' => [$userPasswordField], - 'properties' => [ - $userPasswordField => ['type' => 'string'], - ], - ]; - } - - $userAuthorizedFields = $provider->getUserAuthorizedFields(); - foreach ($userAuthorizedFields as $userAuthorizedField) { - if (!\array_key_exists($userAuthorizedField, $requestProperties)) { - $requestProperties[$userAuthorizedField] = [ - 'type' => 'object', - 'required' => [$userAuthorizedField], - 'properties' => [ - $userAuthorizedField => [ - 'type' => ['string', 'integer'], - ], - ], - ]; - } - } - } - $resetSchema = 1 < \count($resetProperties) ? ['oneOf' => array_values($resetProperties)] : array_values($resetProperties)[0]; - $requestSchema = 1 < \count($requestProperties) ? ['oneOf' => array_values($requestProperties)] : array_values($requestProperties)[0]; - - $schemas['ForgotPassword:reset'] = new \ArrayObject($resetSchema); - - $schemas['ForgotPassword:request'] = new \ArrayObject($requestSchema); - - $schemas['ForgotPassword:validate'] = new \ArrayObject([ - 'type' => ['object', 'null'], - ]); - - $resetForgotPasswordPath = $routes->get('coop_tilleuls_forgot_password.reset')->getPath(); - $paths->addPath($resetForgotPasswordPath, ($paths->getPath($resetForgotPasswordPath) ?: (class_exists(PathItem::class) ? new PathItem() : new LegacyPathItem())) - ->withRef('ForgotPassword') - ->withPost((class_exists(Operation::class) ? new Operation() : new LegacyOperation()) - ->withOperationId('postForgotPassword') - ->withTags(['Forgot password']) - ->withResponses([ - 204 => [ - 'description' => 'Valid email address, no matter if user exists or not', - ], - 400 => [ - 'description' => 'Missing email parameter or invalid format', - ], - ]) - ->withSummary('Generates a token and send email') - ->withParameters([ - [ - 'name' => 'FP-provider', - 'in' => 'header', - 'required' => false, - 'schema' => [ - 'type' => 'string', - ], - ], - ]) - ->withRequestBody((class_exists(RequestBody::class) ? new RequestBody() : new LegacyRequestBody()) - ->withDescription('Request a new password') - ->withRequired(true) - ->withContent(new \ArrayObject([ - 'application/json' => [ - 'schema' => [ - '$ref' => '#/components/schemas/ForgotPassword:request', - ], - ], - ]) - ) - ) - ) - ); - - $getForgotPasswordPath = $routes->get('coop_tilleuls_forgot_password.get_token')->getPath(); - $paths->addPath($getForgotPasswordPath, ($paths->getPath($getForgotPasswordPath) ?: (class_exists(PathItem::class) ? new PathItem() : new LegacyPathItem())) - ->withRef('ForgotPassword') - ->withGet((class_exists(Operation::class) ? new Operation() : new LegacyOperation()) - ->withOperationId('getForgotPassword') - ->withTags(['Forgot password']) - ->withResponses([ - 200 => [ - 'description' => 'Authenticated user', - 'content' => [ - 'application/json' => [ - 'schema' => [ - '$ref' => '#/components/schemas/ForgotPassword:validate', - ], - ], - ], - ], - 404 => [ - 'description' => 'Token not found or expired', - ], - ]) - ->withSummary('Validates token') - ->withParameters([ - [ - 'name' => 'tokenValue', - 'in' => 'path', - 'required' => true, - 'schema' => [ - 'type' => 'string', - ], - ], - [ - 'name' => 'FP-provider', - 'in' => 'header', - 'required' => false, - 'schema' => [ - 'type' => 'string', - ], - ], - ], - ) - ) - ); - - $updateForgotPasswordPath = $routes->get('coop_tilleuls_forgot_password.update')->getPath(); - $paths->addPath($updateForgotPasswordPath, ($paths->getPath($updateForgotPasswordPath) ?: (class_exists(PathItem::class) ? new PathItem() : new LegacyPathItem())) - ->withRef('ForgotPassword') - ->withPost((class_exists(Operation::class) ? new Operation() : new LegacyOperation()) - ->withOperationId('postForgotPasswordToken') - ->withTags(['Forgot password']) - ->withResponses([ - 204 => [ - 'description' => 'Email address format valid, no matter if user exists or not', - ], - 400 => [ - 'description' => 'Missing password parameter', - ], - 404 => [ - 'description' => 'Token not found', - ], - ]) - ->withSummary('Validates token') - ->withParameters([ - [ - 'name' => 'tokenValue', - 'in' => 'path', - 'required' => true, - 'schema' => [ - 'type' => 'string', - ], - ], - [ - 'name' => 'FP-provider', - 'in' => 'header', - 'required' => false, - 'schema' => [ - 'type' => 'string', - ], - ], - ]) - ->withRequestBody((class_exists(RequestBody::class) ? new RequestBody() : new LegacyRequestBody()) - ->withDescription('Reset password') - ->withRequired(true) - ->withContent(new \ArrayObject([ - 'application/json' => [ - 'schema' => [ - '$ref' => '#/components/schemas/ForgotPassword:reset', - ], - ], - ]) - ) - ) - ) - ); - - return $openApi; - } -} diff --git a/src/Bridge/ApiPlatform/OpenApi/OpenApiFactory.php b/src/Bridge/ApiPlatform/OpenApi/OpenApiFactory.php index 32c815c..d6f7f5d 100644 --- a/src/Bridge/ApiPlatform/OpenApi/OpenApiFactory.php +++ b/src/Bridge/ApiPlatform/OpenApi/OpenApiFactory.php @@ -13,37 +13,208 @@ namespace CoopTilleuls\ForgotPasswordBundle\Bridge\ApiPlatform\OpenApi; -use ApiPlatform\Core\OpenApi\Factory\OpenApiFactoryInterface as LegacyOpenApiFactoryInterface; -use ApiPlatform\Core\OpenApi\OpenApi as LegacyOpenApi; use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface; +use ApiPlatform\OpenApi\Model\Operation; +use ApiPlatform\OpenApi\Model\PathItem; +use ApiPlatform\OpenApi\Model\RequestBody; use ApiPlatform\OpenApi\OpenApi; use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderChainInterface; use Symfony\Component\Routing\RouterInterface; -if (interface_exists(OpenApiFactoryInterface::class)) { - final class OpenApiFactory extends AbstractOpenApiFactory implements OpenApiFactoryInterface - { - public function __construct(OpenApiFactoryInterface $decorated, RouterInterface $router, ProviderChainInterface $providerChain) - { - parent::__construct($decorated, $router, $providerChain); - } - - public function __invoke(array $context = []): OpenApi - { - return parent::__invoke($context); - } +/** + * @author Vincent CHALAMON + */ +final class OpenApiFactory implements OpenApiFactoryInterface +{ + public function __construct( + protected readonly OpenApiFactoryInterface $decorated, + protected readonly RouterInterface $router, + protected readonly ProviderChainInterface $providerChain + ) { } -} else { - final class OpenApiFactory extends AbstractOpenApiFactory implements LegacyOpenApiFactoryInterface + + public function __invoke(array $context = []): OpenApi { - public function __construct(LegacyOpenApiFactoryInterface $decorated, RouterInterface $router, ProviderChainInterface $providerChain) - { - parent::__construct($decorated, $router, $providerChain); - } + $routes = $this->router->getRouteCollection(); + $openApi = ($this->decorated)($context); + $schemas = $openApi->getComponents()->getSchemas(); + $paths = $openApi->getPaths(); + + $resetProperties = []; + $requestProperties = []; + foreach ($this->providerChain->all() as $provider) { + $userPasswordField = $provider->getUserPasswordField(); + if (!\array_key_exists($userPasswordField, $resetProperties)) { + $resetProperties[$userPasswordField] = [ + 'type' => 'object', + 'required' => [$userPasswordField], + 'properties' => [ + $userPasswordField => ['type' => 'string'], + ], + ]; + } - public function __invoke(array $context = []): LegacyOpenApi - { - return parent::__invoke($context); + $userAuthorizedFields = $provider->getUserAuthorizedFields(); + foreach ($userAuthorizedFields as $userAuthorizedField) { + if (!\array_key_exists($userAuthorizedField, $requestProperties)) { + $requestProperties[$userAuthorizedField] = [ + 'type' => 'object', + 'required' => [$userAuthorizedField], + 'properties' => [ + $userAuthorizedField => [ + 'type' => ['string', 'integer'], + ], + ], + ]; + } + } } + $resetSchema = 1 < \count($resetProperties) ? ['oneOf' => array_values($resetProperties)] : array_values($resetProperties)[0]; + $requestSchema = 1 < \count($requestProperties) ? ['oneOf' => array_values($requestProperties)] : array_values($requestProperties)[0]; + + $schemas['ForgotPassword:reset'] = new \ArrayObject($resetSchema); + + $schemas['ForgotPassword:request'] = new \ArrayObject($requestSchema); + + $schemas['ForgotPassword:validate'] = new \ArrayObject([ + 'type' => ['object', 'null'], + ]); + + $resetForgotPasswordPath = $routes->get('coop_tilleuls_forgot_password.reset')->getPath(); + $paths->addPath($resetForgotPasswordPath, ($paths->getPath($resetForgotPasswordPath) ?: new PathItem()) + ->withRef('ForgotPassword') + ->withPost((new Operation()) + ->withOperationId('postForgotPassword') + ->withTags(['Forgot password']) + ->withResponses([ + 204 => [ + 'description' => 'Valid email address, no matter if user exists or not', + ], + 400 => [ + 'description' => 'Missing email parameter or invalid format', + ], + ]) + ->withSummary('Generates a token and send email') + ->withParameters([ + [ + 'name' => 'FP-provider', + 'in' => 'header', + 'required' => false, + 'schema' => [ + 'type' => 'string', + ], + ], + ]) + ->withRequestBody((new RequestBody()) + ->withDescription('Request a new password') + ->withRequired(true) + ->withContent(new \ArrayObject([ + 'application/json' => [ + 'schema' => [ + '$ref' => '#/components/schemas/ForgotPassword:request', + ], + ], + ]) + ) + ) + ) + ); + + $getForgotPasswordPath = $routes->get('coop_tilleuls_forgot_password.get_token')->getPath(); + $paths->addPath($getForgotPasswordPath, ($paths->getPath($getForgotPasswordPath) ?: new PathItem()) + ->withRef('ForgotPassword') + ->withGet((new Operation()) + ->withOperationId('getForgotPassword') + ->withTags(['Forgot password']) + ->withResponses([ + 200 => [ + 'description' => 'Authenticated user', + 'content' => [ + 'application/json' => [ + 'schema' => [ + '$ref' => '#/components/schemas/ForgotPassword:validate', + ], + ], + ], + ], + 404 => [ + 'description' => 'Token not found or expired', + ], + ]) + ->withSummary('Validates token') + ->withParameters([ + [ + 'name' => 'tokenValue', + 'in' => 'path', + 'required' => true, + 'schema' => [ + 'type' => 'string', + ], + ], + [ + 'name' => 'FP-provider', + 'in' => 'header', + 'required' => false, + 'schema' => [ + 'type' => 'string', + ], + ], + ], + ) + ) + ); + + $updateForgotPasswordPath = $routes->get('coop_tilleuls_forgot_password.update')->getPath(); + $paths->addPath($updateForgotPasswordPath, ($paths->getPath($updateForgotPasswordPath) ?: new PathItem()) + ->withRef('ForgotPassword') + ->withPost((new Operation()) + ->withOperationId('postForgotPasswordToken') + ->withTags(['Forgot password']) + ->withResponses([ + 204 => [ + 'description' => 'Email address format valid, no matter if user exists or not', + ], + 400 => [ + 'description' => 'Missing password parameter', + ], + 404 => [ + 'description' => 'Token not found', + ], + ]) + ->withSummary('Validates token') + ->withParameters([ + [ + 'name' => 'tokenValue', + 'in' => 'path', + 'required' => true, + 'schema' => [ + 'type' => 'string', + ], + ], + [ + 'name' => 'FP-provider', + 'in' => 'header', + 'required' => false, + 'schema' => [ + 'type' => 'string', + ], + ], + ]) + ->withRequestBody((new RequestBody()) + ->withDescription('Reset password') + ->withRequired(true) + ->withContent(new \ArrayObject([ + 'application/json' => [ + 'schema' => [ + '$ref' => '#/components/schemas/ForgotPassword:reset', + ], + ], + ]) + ) + ) + ) + ); + + return $openApi; } } diff --git a/src/DependencyInjection/BCExtensionTrait.php b/src/DependencyInjection/BCExtensionTrait.php index a5ab545..a90971d 100644 --- a/src/DependencyInjection/BCExtensionTrait.php +++ b/src/DependencyInjection/BCExtensionTrait.php @@ -37,23 +37,6 @@ public function load(array $configs, ContainerBuilder $container): void throw new InvalidConfigurationException('Multiple "ForgotPassword" providers have been defined but none of them is set as default. Did you forget to set "default" option?'); } - // Build parameters - $container->setParameter('coop_tilleuls_forgot_password.password_token_class', $defaultProvider['password_token']['class']); - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.password_token_class'); - $container->setParameter('coop_tilleuls_forgot_password.password_token_expires_in', $defaultProvider['password_token']['expires_in']); - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.password_token_expires_in'); - $container->setParameter('coop_tilleuls_forgot_password.password_token_user_field', $defaultProvider['password_token']['user_field']); - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.password_token_user_field'); - $container->setParameter('coop_tilleuls_forgot_password.password_token_serialization_groups', $defaultProvider['password_token']['serialization_groups']); - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.password_token_serialization_groups'); - $container->setParameter('coop_tilleuls_forgot_password.user_class', $defaultProvider['user']['class']); - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.user_class'); - $authorizedFields = array_unique(array_merge($defaultProvider['user']['authorized_fields'], [$defaultProvider['user']['email_field']])); - $container->setParameter('coop_tilleuls_forgot_password.user_authorized_fields', $authorizedFields); - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.user_authorized_fields'); - $container->setParameter('coop_tilleuls_forgot_password.user_password_field', $defaultProvider['user']['password_field']); - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.user_password_field'); - $this->buildProvider($config, $container); $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../config')); diff --git a/src/Exception/MissingFieldHttpException.php b/src/Exception/MissingFieldHttpException.php index 8e37987..1c893ce 100644 --- a/src/Exception/MissingFieldHttpException.php +++ b/src/Exception/MissingFieldHttpException.php @@ -22,7 +22,6 @@ final class MissingFieldHttpException extends HttpException implements JsonHttpE { public function __construct($fieldName) { - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Status code will change to "%s" in 2.0.', 422); - parent::__construct(400, \sprintf('Parameter "%s" is missing.', $fieldName)); + parent::__construct(422, \sprintf('Parameter "%s" is missing.', $fieldName)); } } diff --git a/src/Manager/ForgotPasswordManager.php b/src/Manager/ForgotPasswordManager.php index 96437db..3bd3505 100644 --- a/src/Manager/ForgotPasswordManager.php +++ b/src/Manager/ForgotPasswordManager.php @@ -18,8 +18,6 @@ use CoopTilleuls\ForgotPasswordBundle\Event\ForgotPasswordEvent; use CoopTilleuls\ForgotPasswordBundle\Event\UpdatePasswordEvent; use CoopTilleuls\ForgotPasswordBundle\Event\UserNotFoundEvent; -use CoopTilleuls\ForgotPasswordBundle\Provider\Provider; -use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderChainInterface; use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface; @@ -29,18 +27,12 @@ */ class ForgotPasswordManager { - public function __construct(private readonly PasswordTokenManager $passwordTokenManager, private readonly EventDispatcherInterface $dispatcher, private readonly ProviderChainInterface $providerChain) + public function __construct(private readonly PasswordTokenManager $passwordTokenManager, private readonly EventDispatcherInterface $dispatcher) { } - public function resetPassword($propertyName, $value, ?ProviderInterface $provider = null): void + public function resetPassword($propertyName, $value, ProviderInterface $provider): void { - /* @var null|Provider $provider */ - if (!$provider) { - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Parameter "%s" in method "%s" is recommended since 1.5 and will be mandatory in 2.0.', '$provider', __METHOD__); - $provider = $this->providerChain->get(); - } - $context = [$propertyName => $value]; $user = $provider->getManager()->findOneBy($provider->getUserClass(), $context); @@ -78,14 +70,8 @@ public function resetPassword($propertyName, $value, ?ProviderInterface $provide * * @return bool */ - public function updatePassword(AbstractPasswordToken $passwordToken, $password, ?ProviderInterface $provider = null) + public function updatePassword(AbstractPasswordToken $passwordToken, $password, ProviderInterface $provider) { - /* @var null|Provider $provider */ - if (!$provider) { - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Parameter "%s" in method "%s" is recommended since 1.5 and will be mandatory in 2.0.', '$provider', __METHOD__); - $provider = $this->providerChain->get(); - } - // Update user password if ($this->dispatcher instanceof ContractsEventDispatcherInterface) { $this->dispatcher->dispatch(new UpdatePasswordEvent($passwordToken, $password)); diff --git a/src/Manager/PasswordTokenManager.php b/src/Manager/PasswordTokenManager.php index 258c3ff..6f045e1 100644 --- a/src/Manager/PasswordTokenManager.php +++ b/src/Manager/PasswordTokenManager.php @@ -14,8 +14,6 @@ namespace CoopTilleuls\ForgotPasswordBundle\Manager; use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken; -use CoopTilleuls\ForgotPasswordBundle\Provider\Provider; -use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderChainInterface; use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderInterface; use CoopTilleuls\ForgotPasswordBundle\TokenGenerator\TokenGeneratorInterface; @@ -24,21 +22,15 @@ */ class PasswordTokenManager { - public function __construct(private readonly ProviderChainInterface $providerChain, private readonly TokenGeneratorInterface $tokenGenerator) + public function __construct(private readonly TokenGeneratorInterface $tokenGenerator) { } /** * @return AbstractPasswordToken */ - public function createPasswordToken($user, ?\DateTime $expiresAt = null, ?ProviderInterface $provider = null) + public function createPasswordToken($user, ?\DateTime $expiresAt = null, ProviderInterface $provider) { - /* @var Provider $provider */ - if (!$provider) { - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Parameter "%s" in method "%s" is recommended since 1.5 and will be mandatory in 2.0.', '$provider', __METHOD__); - $provider = $this->providerChain->get(); - } - if (!$expiresAt) { $expiresAt = new \DateTime($provider->getPasswordTokenExpiredIn()); $expiresAt->setTime((int) $expiresAt->format('H'), (int) $expiresAt->format('i'), (int) $expiresAt->format('s'), 0); @@ -61,28 +53,16 @@ public function createPasswordToken($user, ?\DateTime $expiresAt = null, ?Provid * * @return AbstractPasswordToken */ - public function findOneByToken($token, ?ProviderInterface $provider = null) + public function findOneByToken($token, ProviderInterface $provider) { - /* @var null|Provider $provider */ - if (!$provider) { - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Parameter "%s" in method "%s" is recommended since 1.5 and will be mandatory in 2.0.', '$provider', __METHOD__); - $provider = $this->providerChain->get(); - } - return $provider->getManager()->findOneBy($provider->getPasswordTokenClass(), ['token' => $token]); } /** * @return AbstractPasswordToken */ - public function findOneByUser($user, ?ProviderInterface $provider = null) + public function findOneByUser($user, ProviderInterface $provider) { - /* @var null|Provider $provider */ - if (!$provider) { - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Parameter "%s" in method "%s" is recommended since 1.5 and will be mandatory in 2.0.', '$provider', __METHOD__); - $provider = $this->providerChain->get(); - } - return $provider->getManager()->findOneBy($provider->getPasswordTokenClass(), [$provider->getPasswordTokenUserField() => $user]); } }