From 7e8fb10adabed370d6d4e9f13ac67a0d3507a8cd Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Mon, 10 Jun 2024 16:32:38 +0300 Subject: [PATCH 1/2] Issue #266: Replaced annotation-based DI with attribute-based DI Signed-off-by: alexmerlin --- composer.json | 4 +- config/config.php | 2 +- src/Admin/src/ConfigProvider.php | 18 ++++----- src/Admin/src/Handler/AdminAccountHandler.php | 16 ++++---- src/Admin/src/Handler/AdminHandler.php | 16 ++++---- src/Admin/src/Handler/AdminRoleHandler.php | 16 ++++---- src/Admin/src/Repository/AdminRepository.php | 4 +- .../src/Repository/AdminRoleRepository.php | 4 +- src/Admin/src/Service/AdminRoleService.php | 12 +++--- src/Admin/src/Service/AdminService.php | 14 +++---- src/App/src/ConfigProvider.php | 12 +++--- src/App/src/Handler/ErrorReportHandler.php | 20 ++++------ src/App/src/Handler/HomeHandler.php | 14 +++---- .../Middleware/AuthorizationMiddleware.php | 16 ++++---- .../ContentNegotiationMiddleware.php | 13 +++--- .../Middleware/ErrorResponseMiddleware.php | 12 +++--- .../Repository/OAuthAccessTokenRepository.php | 2 + .../Repository/OAuthAuthCodeRepository.php | 2 + .../src/Repository/OAuthClientRepository.php | 10 ++++- .../OAuthRefreshTokenRepository.php | 2 + .../src/Repository/OAuthScopeRepository.php | 10 ++++- src/App/src/Service/ErrorReportService.php | 10 ++--- src/User/src/ConfigProvider.php | 40 ++++++++++--------- src/User/src/Entity/User.php | 12 +++--- ...sswordEntity.php => UserResetPassword.php} | 2 +- .../EventListener/UserAvatarEventListener.php | 14 ++----- .../src/Handler/AccountActivateHandler.php | 16 ++++---- src/User/src/Handler/AccountAvatarHandler.php | 16 ++++---- src/User/src/Handler/AccountHandler.php | 16 ++++---- .../src/Handler/AccountRecoveryHandler.php | 16 ++++---- .../Handler/AccountResetPasswordHandler.php | 16 ++++---- src/User/src/Handler/UserActivateHandler.php | 16 ++++---- src/User/src/Handler/UserAvatarHandler.php | 18 ++++----- src/User/src/Handler/UserHandler.php | 16 ++++---- src/User/src/Handler/UserRoleHandler.php | 16 ++++---- .../src/Repository/UserAvatarRepository.php | 4 +- .../src/Repository/UserDetailRepository.php | 5 ++- src/User/src/Repository/UserRepository.php | 4 +- .../UserResetPasswordRepository.php | 5 ++- .../src/Repository/UserRoleRepository.php | 4 +- src/User/src/Service/UserAvatarService.php | 14 +++---- src/User/src/Service/UserRoleService.php | 12 +++--- src/User/src/Service/UserService.php | 36 ++++++++--------- src/User/src/Service/UserServiceInterface.php | 4 +- test/Functional/UserTest.php | 14 +++---- 45 files changed, 259 insertions(+), 286 deletions(-) rename src/User/src/Entity/{UserResetPasswordEntity.php => UserResetPassword.php} (98%) diff --git a/composer.json b/composer.json index 26ad77d..e0f18a2 100644 --- a/composer.json +++ b/composer.json @@ -49,12 +49,12 @@ }, "require": { "php": "~8.2.0 || ~8.3.0", - "ext-json": "*", "ext-gd": "*", - "dotkernel/dot-annotated-services": "^4.1.7", + "ext-json": "*", "dotkernel/dot-cache": "^4.0", "dotkernel/dot-cli": "^3.5.0", "dotkernel/dot-data-fixtures": "^1.1.3", + "dotkernel/dot-dependency-injection": "^1.0", "dotkernel/dot-errorhandler": "^3.3.2", "dotkernel/dot-mail": "^4.1.1", "dotkernel/dot-response-header": "^3.2.3", diff --git a/config/config.php b/config/config.php index 7fccec4..42959d6 100644 --- a/config/config.php +++ b/config/config.php @@ -44,7 +44,7 @@ class_exists(Mezzio\Tooling\ConfigProvider::class) Dot\Cli\ConfigProvider::class, Dot\Log\ConfigProvider::class, Dot\ErrorHandler\ConfigProvider::class, - Dot\AnnotatedServices\ConfigProvider::class, + Dot\DependencyInjection\ConfigProvider::class, Dot\ResponseHeader\ConfigProvider::class, Dot\Mail\ConfigProvider::class, Dot\DataFixtures\ConfigProvider::class, diff --git a/src/Admin/src/ConfigProvider.php b/src/Admin/src/ConfigProvider.php index 7ed44e6..9356e0e 100644 --- a/src/Admin/src/ConfigProvider.php +++ b/src/Admin/src/ConfigProvider.php @@ -20,8 +20,8 @@ use Api\Admin\Service\AdminService; use Api\Admin\Service\AdminServiceInterface; use Api\App\ConfigProvider as AppConfigProvider; -use Dot\AnnotatedServices\Factory\AnnotatedRepositoryFactory; -use Dot\AnnotatedServices\Factory\AnnotatedServiceFactory; +use Dot\DependencyInjection\Factory\AttributedRepositoryFactory; +use Dot\DependencyInjection\Factory\AttributedServiceFactory; use Mezzio\Hal\Metadata\MetadataMap; class ConfigProvider @@ -38,14 +38,14 @@ public function getDependencies(): array { return [ 'factories' => [ - AdminHandler::class => AnnotatedServiceFactory::class, - AdminAccountHandler::class => AnnotatedServiceFactory::class, - AdminRoleHandler::class => AnnotatedServiceFactory::class, - AdminService::class => AnnotatedServiceFactory::class, - AdminRoleService::class => AnnotatedServiceFactory::class, + AdminHandler::class => AttributedServiceFactory::class, + AdminAccountHandler::class => AttributedServiceFactory::class, + AdminRoleHandler::class => AttributedServiceFactory::class, + AdminService::class => AttributedServiceFactory::class, + AdminRoleService::class => AttributedServiceFactory::class, AdminCreateCommand::class => AdminCreateCommandFactory::class, - AdminRepository::class => AnnotatedRepositoryFactory::class, - AdminRoleRepository::class => AnnotatedRepositoryFactory::class, + AdminRepository::class => AttributedRepositoryFactory::class, + AdminRoleRepository::class => AttributedRepositoryFactory::class, ], 'aliases' => [ AdminServiceInterface::class => AdminService::class, diff --git a/src/Admin/src/Handler/AdminAccountHandler.php b/src/Admin/src/Handler/AdminAccountHandler.php index e950fed..06a0a9c 100644 --- a/src/Admin/src/Handler/AdminAccountHandler.php +++ b/src/Admin/src/Handler/AdminAccountHandler.php @@ -11,7 +11,7 @@ use Api\App\Exception\ConflictException; use Api\App\Exception\NotFoundException; use Api\App\Handler\HandlerTrait; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; use Psr\Http\Message\ResponseInterface; @@ -22,14 +22,12 @@ class AdminAccountHandler implements RequestHandlerInterface { use HandlerTrait; - /** - * @Inject({ - * HalResponseFactory::class, - * ResourceGenerator::class, - * AdminServiceInterface::class, - * "config" - * }) - */ + #[Inject( + HalResponseFactory::class, + ResourceGenerator::class, + AdminServiceInterface::class, + "config", + )] public function __construct( protected HalResponseFactory $responseFactory, protected ResourceGenerator $resourceGenerator, diff --git a/src/Admin/src/Handler/AdminHandler.php b/src/Admin/src/Handler/AdminHandler.php index 349613f..71ae410 100644 --- a/src/Admin/src/Handler/AdminHandler.php +++ b/src/Admin/src/Handler/AdminHandler.php @@ -11,7 +11,7 @@ use Api\App\Exception\ConflictException; use Api\App\Exception\NotFoundException; use Api\App\Handler\HandlerTrait; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; use Psr\Http\Message\ResponseInterface; @@ -22,14 +22,12 @@ class AdminHandler implements RequestHandlerInterface { use HandlerTrait; - /** - * @Inject({ - * HalResponseFactory::class, - * ResourceGenerator::class, - * AdminServiceInterface::class, - * "config", - * }) - */ + #[Inject( + HalResponseFactory::class, + ResourceGenerator::class, + AdminServiceInterface::class, + "config", + )] public function __construct( protected HalResponseFactory $responseFactory, protected ResourceGenerator $resourceGenerator, diff --git a/src/Admin/src/Handler/AdminRoleHandler.php b/src/Admin/src/Handler/AdminRoleHandler.php index 9067672..1423417 100644 --- a/src/Admin/src/Handler/AdminRoleHandler.php +++ b/src/Admin/src/Handler/AdminRoleHandler.php @@ -7,7 +7,7 @@ use Api\Admin\Service\AdminRoleServiceInterface; use Api\App\Exception\NotFoundException; use Api\App\Handler\HandlerTrait; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; use Psr\Http\Message\ResponseInterface; @@ -18,14 +18,12 @@ class AdminRoleHandler implements RequestHandlerInterface { use HandlerTrait; - /** - * @Inject({ - * HalResponseFactory::class, - * ResourceGenerator::class, - * AdminRoleServiceInterface::class, - * "config" - * }) - */ + #[Inject( + HalResponseFactory::class, + ResourceGenerator::class, + AdminRoleServiceInterface::class, + "config", + )] public function __construct( protected HalResponseFactory $responseFactory, protected ResourceGenerator $resourceGenerator, diff --git a/src/Admin/src/Repository/AdminRepository.php b/src/Admin/src/Repository/AdminRepository.php index d7f4954..15d7e07 100644 --- a/src/Admin/src/Repository/AdminRepository.php +++ b/src/Admin/src/Repository/AdminRepository.php @@ -10,12 +10,12 @@ use Api\App\Helper\PaginationHelper; use Api\App\Message; use Doctrine\ORM\EntityRepository; -use Dot\AnnotatedServices\Annotation\Entity; +use Dot\DependencyInjection\Attribute\Entity; /** - * @Entity(name="Api\Admin\Entity\Admin") * @extends EntityRepository */ +#[Entity(name: Admin::class)] class AdminRepository extends EntityRepository { public function deleteAdmin(Admin $admin): void diff --git a/src/Admin/src/Repository/AdminRoleRepository.php b/src/Admin/src/Repository/AdminRoleRepository.php index 41b4cfc..b9f7a1d 100644 --- a/src/Admin/src/Repository/AdminRoleRepository.php +++ b/src/Admin/src/Repository/AdminRoleRepository.php @@ -8,12 +8,12 @@ use Api\Admin\Entity\AdminRole; use Api\App\Helper\PaginationHelper; use Doctrine\ORM\EntityRepository; -use Dot\AnnotatedServices\Annotation\Entity; +use Dot\DependencyInjection\Attribute\Entity; /** - * @Entity(name="Api\Admin\Entity\AdminRole") * @extends EntityRepository */ +#[Entity(name: AdminRole::class)] class AdminRoleRepository extends EntityRepository { public function getAdminRoles(array $filters = []): AdminRoleCollection diff --git a/src/Admin/src/Service/AdminRoleService.php b/src/Admin/src/Service/AdminRoleService.php index 64101ce..b38d033 100644 --- a/src/Admin/src/Service/AdminRoleService.php +++ b/src/Admin/src/Service/AdminRoleService.php @@ -9,17 +9,15 @@ use Api\Admin\Repository\AdminRoleRepository; use Api\App\Exception\NotFoundException; use Api\App\Message; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; class AdminRoleService implements AdminRoleServiceInterface { - /** - * @Inject({ - * AdminRoleRepository::class - * }) - */ + #[Inject( + AdminRoleRepository::class, + )] public function __construct( - protected AdminRoleRepository $adminRoleRepository + protected AdminRoleRepository $adminRoleRepository, ) { } diff --git a/src/Admin/src/Service/AdminService.php b/src/Admin/src/Service/AdminService.php index 53d4bac..d596776 100644 --- a/src/Admin/src/Service/AdminService.php +++ b/src/Admin/src/Service/AdminService.php @@ -11,19 +11,17 @@ use Api\App\Exception\ConflictException; use Api\App\Exception\NotFoundException; use Api\App\Message; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; class AdminService implements AdminServiceInterface { - /** - * @Inject({ - * AdminRoleService::class, - * AdminRepository::class - * }) - */ + #[Inject( + AdminRoleService::class, + AdminRepository::class, + )] public function __construct( protected AdminRoleService $adminRoleService, - protected AdminRepository $adminRepository + protected AdminRepository $adminRepository, ) { } diff --git a/src/App/src/ConfigProvider.php b/src/App/src/ConfigProvider.php index bd5d44d..2c982b5 100644 --- a/src/App/src/ConfigProvider.php +++ b/src/App/src/ConfigProvider.php @@ -20,7 +20,7 @@ use Api\App\Service\ErrorReportServiceInterface; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; -use Dot\AnnotatedServices\Factory\AnnotatedServiceFactory; +use Dot\DependencyInjection\Factory\AttributedServiceFactory; use Dot\Mail\Factory\MailOptionsAbstractFactory; use Dot\Mail\Factory\MailServiceAbstractFactory; use Dot\Mail\Service\MailService; @@ -64,16 +64,16 @@ public function getDependencies(): array 'dot-mail.options.default' => MailOptionsAbstractFactory::class, 'dot-mail.service.default' => MailServiceAbstractFactory::class, AuthenticationMiddleware::class => AuthenticationMiddlewareFactory::class, - AuthorizationMiddleware::class => AnnotatedServiceFactory::class, - ContentNegotiationMiddleware::class => AnnotatedServiceFactory::class, + AuthorizationMiddleware::class => AttributedServiceFactory::class, + ContentNegotiationMiddleware::class => AttributedServiceFactory::class, Environment::class => TwigEnvironmentFactory::class, TwigExtension::class => TwigExtensionFactory::class, TwigRenderer::class => TwigRendererFactory::class, - HomeHandler::class => AnnotatedServiceFactory::class, - ErrorResponseMiddleware::class => AnnotatedServiceFactory::class, + HomeHandler::class => AttributedServiceFactory::class, + ErrorResponseMiddleware::class => AttributedServiceFactory::class, RouteListCommand::class => RouteListCommandFactory::class, TokenGenerateCommand::class => TokenGenerateCommandFactory::class, - ErrorReportService::class => AnnotatedServiceFactory::class, + ErrorReportService::class => AttributedServiceFactory::class, EntityListenerResolver::class => EntityListenerResolverFactory::class, ], 'aliases' => [ diff --git a/src/App/src/Handler/ErrorReportHandler.php b/src/App/src/Handler/ErrorReportHandler.php index fb355fa..5546af3 100644 --- a/src/App/src/Handler/ErrorReportHandler.php +++ b/src/App/src/Handler/ErrorReportHandler.php @@ -7,8 +7,7 @@ use Api\App\Exception\ForbiddenException; use Api\App\Message; use Api\App\Service\ErrorReportServiceInterface; -use Dot\AnnotatedServices\Annotation\Inject; -use Dot\AnnotatedServices\Annotation\Service; +use Dot\DependencyInjection\Attribute\Inject; use Fig\Http\Message\StatusCodeInterface; use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; @@ -17,21 +16,16 @@ use Psr\Http\Server\RequestHandlerInterface; use RuntimeException; -/** - * @Service - */ class ErrorReportHandler implements RequestHandlerInterface { use HandlerTrait; - /** - * @Inject({ - * HalResponseFactory::class, - * ResourceGenerator::class, - * ErrorReportServiceInterface::class, - * "config" - * }) - */ + #[Inject( + HalResponseFactory::class, + ResourceGenerator::class, + ErrorReportServiceInterface::class, + "config", + )] public function __construct( protected HalResponseFactory $responseFactory, protected ResourceGenerator $resourceGenerator, diff --git a/src/App/src/Handler/HomeHandler.php b/src/App/src/Handler/HomeHandler.php index d5c1cae..9e8f11d 100644 --- a/src/App/src/Handler/HomeHandler.php +++ b/src/App/src/Handler/HomeHandler.php @@ -4,7 +4,7 @@ namespace Api\App\Handler; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; use Psr\Http\Message\ResponseInterface; @@ -14,13 +14,11 @@ class HomeHandler implements RequestHandlerInterface { use HandlerTrait; - /** - * @Inject({ - * HalResponseFactory::class, - * ResourceGenerator::class, - * "config" - * }) - */ + #[Inject( + HalResponseFactory::class, + ResourceGenerator::class, + "config", + )] public function __construct( protected HalResponseFactory $responseFactory, protected ResourceGenerator $resourceGenerator, diff --git a/src/App/src/Middleware/AuthorizationMiddleware.php b/src/App/src/Middleware/AuthorizationMiddleware.php index 5d840c0..600d446 100644 --- a/src/App/src/Middleware/AuthorizationMiddleware.php +++ b/src/App/src/Middleware/AuthorizationMiddleware.php @@ -12,7 +12,7 @@ use Api\App\UserIdentity; use Api\User\Entity\User; use Api\User\Repository\UserRepository; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Fig\Http\Message\StatusCodeInterface; use Laminas\Diactoros\Response\JsonResponse; use Mezzio\Authentication\UserInterface; @@ -27,17 +27,15 @@ class AuthorizationMiddleware implements MiddlewareInterface { - /** - * @Inject({ - * AuthorizationInterface::class, - * UserRepository::class, - * AdminRepository::class - * }) - */ + #[Inject( + AuthorizationInterface::class, + UserRepository::class, + AdminRepository::class, + )] public function __construct( protected AuthorizationInterface $authorization, protected UserRepository $userRepository, - protected AdminRepository $adminRepository + protected AdminRepository $adminRepository, ) { } diff --git a/src/App/src/Middleware/ContentNegotiationMiddleware.php b/src/App/src/Middleware/ContentNegotiationMiddleware.php index 53c433b..23b0a99 100644 --- a/src/App/src/Middleware/ContentNegotiationMiddleware.php +++ b/src/App/src/Middleware/ContentNegotiationMiddleware.php @@ -5,7 +5,7 @@ namespace Api\App\Middleware; use Api\App\Handler\ResponseTrait; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Mezzio\Router\RouteResult; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -26,11 +26,12 @@ class ContentNegotiationMiddleware implements MiddlewareInterface { use ResponseTrait; - /** - * @Inject({"config.content-negotiation"}) - */ - public function __construct(private array $config) - { + #[Inject( + "config.content-negotiation", + )] + public function __construct( + private array $config, + ) { } public function process( diff --git a/src/App/src/Middleware/ErrorResponseMiddleware.php b/src/App/src/Middleware/ErrorResponseMiddleware.php index 713d628..74db371 100644 --- a/src/App/src/Middleware/ErrorResponseMiddleware.php +++ b/src/App/src/Middleware/ErrorResponseMiddleware.php @@ -4,7 +4,7 @@ namespace Api\App\Middleware; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Fig\Http\Message\StatusCodeInterface; use Laminas\Diactoros\Stream; use Psr\Http\Message\ResponseInterface; @@ -17,13 +17,11 @@ class ErrorResponseMiddleware implements MiddlewareInterface { - /** - * @Inject({ - * "config.authentication" - * }) - */ + #[Inject( + "config.authentication", + )] public function __construct( - protected array $config + protected array $config, ) { } diff --git a/src/App/src/Repository/OAuthAccessTokenRepository.php b/src/App/src/Repository/OAuthAccessTokenRepository.php index 5f3fd13..313cbf4 100644 --- a/src/App/src/Repository/OAuthAccessTokenRepository.php +++ b/src/App/src/Repository/OAuthAccessTokenRepository.php @@ -9,6 +9,7 @@ use Api\App\Entity\OAuthClient; use Api\User\Entity\User; use Doctrine\ORM\EntityRepository; +use Dot\DependencyInjection\Attribute\Entity; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\UserEntityInterface; @@ -17,6 +18,7 @@ /** * @extends EntityRepository */ +#[Entity(name: OAuthAccessToken::class)] class OAuthAccessTokenRepository extends EntityRepository implements AccessTokenRepositoryInterface { /** diff --git a/src/App/src/Repository/OAuthAuthCodeRepository.php b/src/App/src/Repository/OAuthAuthCodeRepository.php index 6fc8ee7..cf4469c 100644 --- a/src/App/src/Repository/OAuthAuthCodeRepository.php +++ b/src/App/src/Repository/OAuthAuthCodeRepository.php @@ -6,12 +6,14 @@ use Api\App\Entity\OAuthAuthCode; use Doctrine\ORM\EntityRepository; +use Dot\DependencyInjection\Attribute\Entity; use League\OAuth2\Server\Entities\AuthCodeEntityInterface; use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface; /** * @extends EntityRepository */ +#[Entity(name: OAuthAuthCode::class)] class OAuthAuthCodeRepository extends EntityRepository implements AuthCodeRepositoryInterface { public function getNewAuthCode(): OAuthAuthCode diff --git a/src/App/src/Repository/OAuthClientRepository.php b/src/App/src/Repository/OAuthClientRepository.php index fe2233d..f5db5e7 100644 --- a/src/App/src/Repository/OAuthClientRepository.php +++ b/src/App/src/Repository/OAuthClientRepository.php @@ -4,7 +4,9 @@ namespace Api\App\Repository; +use Api\App\Entity\OAuthClient; use Doctrine\ORM\EntityRepository; +use Dot\DependencyInjection\Attribute\Entity; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; @@ -14,6 +16,7 @@ /** * @extends EntityRepository */ +#[Entity(name: OAuthClient::class)] class OAuthClientRepository extends EntityRepository implements ClientRepositoryInterface { private const GRANT_TYPE_CLIENT_CREDENTIALS = 'client_credentials'; @@ -33,7 +36,12 @@ class OAuthClientRepository extends EntityRepository implements ClientRepository */ public function getClientEntity($clientIdentifier): ?ClientEntityInterface { - return $this->findOneBy(['name' => $clientIdentifier]); + $client = $this->findOneBy(['name' => $clientIdentifier]); + if ($client instanceof OAuthClient) { + return $client; + } + + return null; } /** diff --git a/src/App/src/Repository/OAuthRefreshTokenRepository.php b/src/App/src/Repository/OAuthRefreshTokenRepository.php index 089cebf..65be1ac 100644 --- a/src/App/src/Repository/OAuthRefreshTokenRepository.php +++ b/src/App/src/Repository/OAuthRefreshTokenRepository.php @@ -6,12 +6,14 @@ use Api\App\Entity\OAuthRefreshToken; use Doctrine\ORM\EntityRepository; +use Dot\DependencyInjection\Attribute\Entity; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; /** * @extends EntityRepository */ +#[Entity(name: OAuthRefreshToken::class)] class OAuthRefreshTokenRepository extends EntityRepository implements RefreshTokenRepositoryInterface { public function getNewRefreshToken(): OAuthRefreshToken diff --git a/src/App/src/Repository/OAuthScopeRepository.php b/src/App/src/Repository/OAuthScopeRepository.php index 3c2f721..8e84ddd 100644 --- a/src/App/src/Repository/OAuthScopeRepository.php +++ b/src/App/src/Repository/OAuthScopeRepository.php @@ -4,7 +4,9 @@ namespace Api\App\Repository; +use Api\App\Entity\OAuthScope; use Doctrine\ORM\EntityRepository; +use Dot\DependencyInjection\Attribute\Entity; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\ScopeEntityInterface; use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; @@ -12,6 +14,7 @@ /** * @extends EntityRepository */ +#[Entity(name: OAuthScope::class)] class OAuthScopeRepository extends EntityRepository implements ScopeRepositoryInterface { /** @@ -19,7 +22,12 @@ class OAuthScopeRepository extends EntityRepository implements ScopeRepositoryIn */ public function getScopeEntityByIdentifier($identifier): ?ScopeEntityInterface { - return $this->findOneBy(['scope' => $identifier]); + $scope = $this->findOneBy(['scope' => $identifier]); + if ($scope instanceof OAuthScope) { + return $scope; + } + + return null; } /** diff --git a/src/App/src/Service/ErrorReportService.php b/src/App/src/Service/ErrorReportService.php index b4f4d0c..af50afe 100644 --- a/src/App/src/Service/ErrorReportService.php +++ b/src/App/src/Service/ErrorReportService.php @@ -7,7 +7,7 @@ use Api\App\Exception\ForbiddenException; use Api\App\Exception\UnauthorizedException; use Api\App\Message; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Psr\Http\Message\ServerRequestInterface; use RuntimeException; use Symfony\Component\Filesystem\Exception\IOException; @@ -31,11 +31,9 @@ class ErrorReportService implements ErrorReportServiceInterface private Filesystem $fileSystem; private ?string $token = null; - /** - * @Inject({ - * "config" - * }) - */ + #[Inject( + "config", + )] public function __construct( protected array $config ) { diff --git a/src/User/src/ConfigProvider.php b/src/User/src/ConfigProvider.php index 76112a2..1ad585b 100644 --- a/src/User/src/ConfigProvider.php +++ b/src/User/src/ConfigProvider.php @@ -10,6 +10,7 @@ use Api\User\Entity\User; use Api\User\Entity\UserAvatar; use Api\User\Entity\UserRole; +use Api\User\EventListener\UserAvatarEventListener; use Api\User\Handler\AccountActivateHandler; use Api\User\Handler\AccountAvatarHandler; use Api\User\Handler\AccountHandler; @@ -30,8 +31,8 @@ use Api\User\Service\UserRoleServiceInterface; use Api\User\Service\UserService; use Api\User\Service\UserServiceInterface; -use Dot\AnnotatedServices\Factory\AnnotatedRepositoryFactory; -use Dot\AnnotatedServices\Factory\AnnotatedServiceFactory; +use Dot\DependencyInjection\Factory\AttributedRepositoryFactory; +use Dot\DependencyInjection\Factory\AttributedServiceFactory; use Mezzio\Hal\Metadata\MetadataMap; class ConfigProvider @@ -49,23 +50,24 @@ public function getDependencies(): array { return [ 'factories' => [ - AccountActivateHandler::class => AnnotatedServiceFactory::class, - AccountAvatarHandler::class => AnnotatedServiceFactory::class, - AccountHandler::class => AnnotatedServiceFactory::class, - AccountResetPasswordHandler::class => AnnotatedServiceFactory::class, - AccountRecoveryHandler::class => AnnotatedServiceFactory::class, - UserActivateHandler::class => AnnotatedServiceFactory::class, - UserAvatarHandler::class => AnnotatedServiceFactory::class, - UserHandler::class => AnnotatedServiceFactory::class, - UserRoleHandler::class => AnnotatedServiceFactory::class, - UserService::class => AnnotatedServiceFactory::class, - UserRoleService::class => AnnotatedServiceFactory::class, - UserAvatarService::class => AnnotatedServiceFactory::class, - UserRepository::class => AnnotatedRepositoryFactory::class, - UserDetailRepository::class => AnnotatedRepositoryFactory::class, - UserResetPasswordRepository::class => AnnotatedRepositoryFactory::class, - UserRoleRepository::class => AnnotatedRepositoryFactory::class, - UserAvatarRepository::class => AnnotatedRepositoryFactory::class, + AccountActivateHandler::class => AttributedServiceFactory::class, + AccountAvatarHandler::class => AttributedServiceFactory::class, + AccountHandler::class => AttributedServiceFactory::class, + AccountResetPasswordHandler::class => AttributedServiceFactory::class, + AccountRecoveryHandler::class => AttributedServiceFactory::class, + UserActivateHandler::class => AttributedServiceFactory::class, + UserAvatarHandler::class => AttributedServiceFactory::class, + UserAvatarEventListener::class => AttributedServiceFactory::class, + UserHandler::class => AttributedServiceFactory::class, + UserRoleHandler::class => AttributedServiceFactory::class, + UserService::class => AttributedServiceFactory::class, + UserRoleService::class => AttributedServiceFactory::class, + UserAvatarService::class => AttributedServiceFactory::class, + UserRepository::class => AttributedRepositoryFactory::class, + UserDetailRepository::class => AttributedRepositoryFactory::class, + UserResetPasswordRepository::class => AttributedRepositoryFactory::class, + UserRoleRepository::class => AttributedRepositoryFactory::class, + UserAvatarRepository::class => AttributedRepositoryFactory::class, ], 'aliases' => [ UserAvatarServiceInterface::class => UserAvatarService::class, diff --git a/src/User/src/Entity/User.php b/src/User/src/Entity/User.php index 445e7cd..8a2871b 100644 --- a/src/User/src/Entity/User.php +++ b/src/User/src/Entity/User.php @@ -37,7 +37,7 @@ class User extends AbstractEntity implements UserEntityInterface #[ORM\OneToOne(mappedBy: "user", targetEntity: UserDetail::class, cascade: ['persist', 'remove'])] protected UserDetail $detail; - #[ORM\OneToMany(mappedBy: "user", targetEntity: UserResetPasswordEntity::class, cascade: ['persist', 'remove'])] + #[ORM\OneToMany(mappedBy: "user", targetEntity: UserResetPassword::class, cascade: ['persist', 'remove'])] protected Collection $resetPasswords; #[ORM\ManyToMany(targetEntity: UserRole::class)] @@ -207,7 +207,7 @@ public function setRoles(array $roles): self return $this; } - public function addResetPassword(UserResetPasswordEntity $resetPassword): void + public function addResetPassword(UserResetPassword $resetPassword): void { $this->resetPasswords->add($resetPassword); } @@ -215,7 +215,7 @@ public function addResetPassword(UserResetPasswordEntity $resetPassword): void public function createResetPassword(): self { $this->resetPasswords->add( - (new UserResetPasswordEntity()) + (new UserResetPassword()) ->setHash(self::generateHash()) ->setUser($this) ); @@ -228,12 +228,12 @@ public function getResetPasswords(): Collection return $this->resetPasswords; } - public function hasResetPassword(UserResetPasswordEntity $resetPassword): bool + public function hasResetPassword(UserResetPassword $resetPassword): bool { return $this->resetPasswords->contains($resetPassword); } - public function removeResetPassword(UserResetPasswordEntity $resetPassword): self + public function removeResetPassword(UserResetPassword $resetPassword): self { $this->resetPasswords->removeElement($resetPassword); @@ -323,7 +323,7 @@ public function getArrayCopy(): array 'roles' => $this->getRoles()->map(function (UserRole $userRole) { return $userRole->getArrayCopy(); })->toArray(), - 'resetPasswords' => $this->getResetPasswords()->map(function (UserResetPasswordEntity $resetPassword) { + 'resetPasswords' => $this->getResetPasswords()->map(function (UserResetPassword $resetPassword) { return $resetPassword->getArrayCopy(); })->toArray(), 'created' => $this->getCreated(), diff --git a/src/User/src/Entity/UserResetPasswordEntity.php b/src/User/src/Entity/UserResetPassword.php similarity index 98% rename from src/User/src/Entity/UserResetPasswordEntity.php rename to src/User/src/Entity/UserResetPassword.php index 382f9b1..a5d916a 100644 --- a/src/User/src/Entity/UserResetPasswordEntity.php +++ b/src/User/src/Entity/UserResetPassword.php @@ -15,7 +15,7 @@ #[ORM\Entity(repositoryClass: UserResetPasswordRepository::class)] #[ORM\Table(name: "user_reset_password")] #[ORM\HasLifecycleCallbacks] -class UserResetPasswordEntity extends AbstractEntity +class UserResetPassword extends AbstractEntity { public const STATUS_COMPLETED = 'completed'; public const STATUS_REQUESTED = 'requested'; diff --git a/src/User/src/EventListener/UserAvatarEventListener.php b/src/User/src/EventListener/UserAvatarEventListener.php index 7a65083..3f96d76 100644 --- a/src/User/src/EventListener/UserAvatarEventListener.php +++ b/src/User/src/EventListener/UserAvatarEventListener.php @@ -5,22 +5,16 @@ namespace Api\User\EventListener; use Api\User\Entity\UserAvatar; -use Dot\AnnotatedServices\Annotation\Inject; -use Dot\AnnotatedServices\Annotation\Service; +use Dot\DependencyInjection\Attribute\Inject; use function rtrim; use function sprintf; -/** - * @Service - */ class UserAvatarEventListener { - /** - * @Inject({ - * "config" - * }) - */ + #[Inject( + "config", + )] public function __construct( protected array $config = [] ) { diff --git a/src/User/src/Handler/AccountActivateHandler.php b/src/User/src/Handler/AccountActivateHandler.php index 099329c..8024f67 100644 --- a/src/User/src/Handler/AccountActivateHandler.php +++ b/src/User/src/Handler/AccountActivateHandler.php @@ -11,7 +11,7 @@ use Api\App\Message; use Api\User\InputFilter\ActivateAccountInputFilter; use Api\User\Service\UserServiceInterface; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Dot\Mail\Exception\MailException; use Fig\Http\Message\StatusCodeInterface; use Mezzio\Hal\HalResponseFactory; @@ -26,14 +26,12 @@ class AccountActivateHandler implements RequestHandlerInterface { use HandlerTrait; - /** - * @Inject({ - * HalResponseFactory::class, - * ResourceGenerator::class, - * UserServiceInterface::class, - * "config" - * }) - */ + #[Inject( + HalResponseFactory::class, + ResourceGenerator::class, + UserServiceInterface::class, + "config", + )] public function __construct( protected HalResponseFactory $responseFactory, protected ResourceGenerator $resourceGenerator, diff --git a/src/User/src/Handler/AccountAvatarHandler.php b/src/User/src/Handler/AccountAvatarHandler.php index be79d6d..3ba78e8 100644 --- a/src/User/src/Handler/AccountAvatarHandler.php +++ b/src/User/src/Handler/AccountAvatarHandler.php @@ -11,7 +11,7 @@ use Api\User\Entity\User; use Api\User\InputFilter\UpdateAvatarInputFilter; use Api\User\Service\UserAvatarServiceInterface; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; use Psr\Http\Message\ResponseInterface; @@ -22,14 +22,12 @@ class AccountAvatarHandler implements RequestHandlerInterface { use HandlerTrait; - /** - * @Inject({ - * HalResponseFactory::class, - * ResourceGenerator::class, - * UserAvatarServiceInterface::class, - * "config" - * }) - */ + #[Inject( + HalResponseFactory::class, + ResourceGenerator::class, + UserAvatarServiceInterface::class, + "config", + )] public function __construct( protected HalResponseFactory $responseFactory, protected ResourceGenerator $resourceGenerator, diff --git a/src/User/src/Handler/AccountHandler.php b/src/User/src/Handler/AccountHandler.php index 5b0e358..b32bd27 100644 --- a/src/User/src/Handler/AccountHandler.php +++ b/src/User/src/Handler/AccountHandler.php @@ -12,7 +12,7 @@ use Api\User\InputFilter\CreateUserInputFilter; use Api\User\InputFilter\UpdateUserInputFilter; use Api\User\Service\UserServiceInterface; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Dot\Mail\Exception\MailException; use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; @@ -25,14 +25,12 @@ class AccountHandler implements RequestHandlerInterface { use HandlerTrait; - /** - * @Inject({ - * HalResponseFactory::class, - * ResourceGenerator::class, - * UserServiceInterface::class, - * "config", - * }) - */ + #[Inject( + HalResponseFactory::class, + ResourceGenerator::class, + UserServiceInterface::class, + "config", + )] public function __construct( protected HalResponseFactory $responseFactory, protected ResourceGenerator $resourceGenerator, diff --git a/src/User/src/Handler/AccountRecoveryHandler.php b/src/User/src/Handler/AccountRecoveryHandler.php index 5227917..98d0393 100644 --- a/src/User/src/Handler/AccountRecoveryHandler.php +++ b/src/User/src/Handler/AccountRecoveryHandler.php @@ -10,7 +10,7 @@ use Api\App\Message; use Api\User\InputFilter\RecoverIdentityInputFilter; use Api\User\Service\UserServiceInterface; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Dot\Mail\Exception\MailException; use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; @@ -22,14 +22,12 @@ class AccountRecoveryHandler implements RequestHandlerInterface { use HandlerTrait; - /** - * @Inject({ - * HalResponseFactory::class, - * ResourceGenerator::class, - * UserServiceInterface::class, - * "config" - * }) - */ + #[Inject( + HalResponseFactory::class, + ResourceGenerator::class, + UserServiceInterface::class, + "config", + )] public function __construct( protected HalResponseFactory $responseFactory, protected ResourceGenerator $resourceGenerator, diff --git a/src/User/src/Handler/AccountResetPasswordHandler.php b/src/User/src/Handler/AccountResetPasswordHandler.php index 97ab3af..5a4ee31 100644 --- a/src/User/src/Handler/AccountResetPasswordHandler.php +++ b/src/User/src/Handler/AccountResetPasswordHandler.php @@ -14,7 +14,7 @@ use Api\User\InputFilter\ResetPasswordInputFilter; use Api\User\InputFilter\UpdatePasswordInputFilter; use Api\User\Service\UserServiceInterface; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Dot\Mail\Exception\MailException; use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; @@ -28,14 +28,12 @@ class AccountResetPasswordHandler implements RequestHandlerInterface { use HandlerTrait; - /** - * @Inject({ - * HalResponseFactory::class, - * ResourceGenerator::class, - * UserServiceInterface::class, - * "config" - * }) - */ + #[Inject( + HalResponseFactory::class, + ResourceGenerator::class, + UserServiceInterface::class, + "config", + )] public function __construct( protected HalResponseFactory $responseFactory, protected ResourceGenerator $resourceGenerator, diff --git a/src/User/src/Handler/UserActivateHandler.php b/src/User/src/Handler/UserActivateHandler.php index f86ffa6..78a63df 100644 --- a/src/User/src/Handler/UserActivateHandler.php +++ b/src/User/src/Handler/UserActivateHandler.php @@ -9,7 +9,7 @@ use Api\App\Handler\HandlerTrait; use Api\App\Message; use Api\User\Service\UserServiceInterface; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Dot\Mail\Exception\MailException; use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; @@ -21,14 +21,12 @@ class UserActivateHandler implements RequestHandlerInterface { use HandlerTrait; - /** - * @Inject({ - * HalResponseFactory::class, - * ResourceGenerator::class, - * UserServiceInterface::class, - * "config" - * }) - */ + #[Inject( + HalResponseFactory::class, + ResourceGenerator::class, + UserServiceInterface::class, + "config", + )] public function __construct( protected HalResponseFactory $responseFactory, protected ResourceGenerator $resourceGenerator, diff --git a/src/User/src/Handler/UserAvatarHandler.php b/src/User/src/Handler/UserAvatarHandler.php index bc2e272..bd22d60 100644 --- a/src/User/src/Handler/UserAvatarHandler.php +++ b/src/User/src/Handler/UserAvatarHandler.php @@ -11,7 +11,7 @@ use Api\User\InputFilter\UpdateAvatarInputFilter; use Api\User\Service\UserAvatarServiceInterface; use Api\User\Service\UserServiceInterface; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; use Psr\Http\Message\ResponseInterface; @@ -22,15 +22,13 @@ class UserAvatarHandler implements RequestHandlerInterface { use HandlerTrait; - /** - * @Inject({ - * HalResponseFactory::class, - * ResourceGenerator::class, - * UserServiceInterface::class, - * UserAvatarServiceInterface::class, - * "config" - * }) - */ + #[Inject( + HalResponseFactory::class, + ResourceGenerator::class, + UserServiceInterface::class, + UserAvatarServiceInterface::class, + "config", + )] public function __construct( protected HalResponseFactory $responseFactory, protected ResourceGenerator $resourceGenerator, diff --git a/src/User/src/Handler/UserHandler.php b/src/User/src/Handler/UserHandler.php index 5937da5..88b50e8 100644 --- a/src/User/src/Handler/UserHandler.php +++ b/src/User/src/Handler/UserHandler.php @@ -11,7 +11,7 @@ use Api\User\InputFilter\CreateUserInputFilter; use Api\User\InputFilter\UpdateUserInputFilter; use Api\User\Service\UserServiceInterface; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Dot\Mail\Exception\MailException; use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; @@ -24,14 +24,12 @@ class UserHandler implements RequestHandlerInterface { use HandlerTrait; - /** - * @Inject({ - * HalResponseFactory::class, - * ResourceGenerator::class, - * UserServiceInterface::class, - * "config" - * }) - */ + #[Inject( + HalResponseFactory::class, + ResourceGenerator::class, + UserServiceInterface::class, + "config", + )] public function __construct( protected HalResponseFactory $responseFactory, protected ResourceGenerator $resourceGenerator, diff --git a/src/User/src/Handler/UserRoleHandler.php b/src/User/src/Handler/UserRoleHandler.php index cb6effc..754d884 100644 --- a/src/User/src/Handler/UserRoleHandler.php +++ b/src/User/src/Handler/UserRoleHandler.php @@ -7,7 +7,7 @@ use Api\App\Exception\NotFoundException; use Api\App\Handler\HandlerTrait; use Api\User\Service\UserRoleServiceInterface; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; use Psr\Http\Message\ResponseInterface; @@ -18,14 +18,12 @@ class UserRoleHandler implements RequestHandlerInterface { use HandlerTrait; - /** - * @Inject({ - * HalResponseFactory::class, - * ResourceGenerator::class, - * UserRoleServiceInterface::class, - * "config" - * }) - */ + #[Inject( + HalResponseFactory::class, + ResourceGenerator::class, + UserRoleServiceInterface::class, + "config", + )] public function __construct( protected HalResponseFactory $responseFactory, protected ResourceGenerator $resourceGenerator, diff --git a/src/User/src/Repository/UserAvatarRepository.php b/src/User/src/Repository/UserAvatarRepository.php index 2537251..7987eaa 100644 --- a/src/User/src/Repository/UserAvatarRepository.php +++ b/src/User/src/Repository/UserAvatarRepository.php @@ -6,12 +6,12 @@ use Api\User\Entity\UserAvatar; use Doctrine\ORM\EntityRepository; -use Dot\AnnotatedServices\Annotation\Entity; +use Dot\DependencyInjection\Attribute\Entity; /** - * @Entity(name="Api\User\Entity\UserAvatar") * @extends EntityRepository */ +#[Entity(name: UserAvatar::class)] class UserAvatarRepository extends EntityRepository { public function deleteAvatar(UserAvatar $avatar): void diff --git a/src/User/src/Repository/UserDetailRepository.php b/src/User/src/Repository/UserDetailRepository.php index 6ec977c..2c8a19d 100644 --- a/src/User/src/Repository/UserDetailRepository.php +++ b/src/User/src/Repository/UserDetailRepository.php @@ -4,13 +4,14 @@ namespace Api\User\Repository; +use Api\User\Entity\UserDetail; use Doctrine\ORM\EntityRepository; -use Dot\AnnotatedServices\Annotation\Entity; +use Dot\DependencyInjection\Attribute\Entity; /** - * @Entity(name="Api\User\Entity\UserDetail") * @extends EntityRepository */ +#[Entity(name: UserDetail::class)] class UserDetailRepository extends EntityRepository { } diff --git a/src/User/src/Repository/UserRepository.php b/src/User/src/Repository/UserRepository.php index 9fd8af0..b26ee0a 100644 --- a/src/User/src/Repository/UserRepository.php +++ b/src/User/src/Repository/UserRepository.php @@ -11,7 +11,7 @@ use Api\User\Collection\UserCollection; use Api\User\Entity\User; use Doctrine\ORM\EntityRepository; -use Dot\AnnotatedServices\Annotation\Entity; +use Dot\DependencyInjection\Attribute\Entity; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Repositories\UserRepositoryInterface; @@ -21,9 +21,9 @@ use function password_verify; /** - * @Entity(name="Api\User\Entity\User") * @extends EntityRepository */ +#[Entity(name: User::class)] class UserRepository extends EntityRepository implements UserRepositoryInterface { public function deleteUser(User $user): void diff --git a/src/User/src/Repository/UserResetPasswordRepository.php b/src/User/src/Repository/UserResetPasswordRepository.php index 72b857e..2143be1 100644 --- a/src/User/src/Repository/UserResetPasswordRepository.php +++ b/src/User/src/Repository/UserResetPasswordRepository.php @@ -4,13 +4,14 @@ namespace Api\User\Repository; +use Api\User\Entity\UserResetPassword; use Doctrine\ORM\EntityRepository; -use Dot\AnnotatedServices\Annotation\Entity; +use Dot\DependencyInjection\Attribute\Entity; /** - * @Entity(name="Api\User\Entity\UserResetPasswordEntity") * @extends EntityRepository */ +#[Entity(name: UserResetPassword::class)] class UserResetPasswordRepository extends EntityRepository { } diff --git a/src/User/src/Repository/UserRoleRepository.php b/src/User/src/Repository/UserRoleRepository.php index fc1b4b7..bb28244 100644 --- a/src/User/src/Repository/UserRoleRepository.php +++ b/src/User/src/Repository/UserRoleRepository.php @@ -8,12 +8,12 @@ use Api\User\Collection\UserRoleCollection; use Api\User\Entity\UserRole; use Doctrine\ORM\EntityRepository; -use Dot\AnnotatedServices\Annotation\Entity; +use Dot\DependencyInjection\Attribute\Entity; /** - * @Entity(name="Api\User\Entity\UserRole") * @extends EntityRepository */ +#[Entity(name: UserRole::class)] class UserRoleRepository extends EntityRepository { public function getRoles(array $params = []): UserRoleCollection diff --git a/src/User/src/Service/UserAvatarService.php b/src/User/src/Service/UserAvatarService.php index c177ce1..4c153dc 100644 --- a/src/User/src/Service/UserAvatarService.php +++ b/src/User/src/Service/UserAvatarService.php @@ -7,7 +7,7 @@ use Api\User\Entity\User; use Api\User\Entity\UserAvatar; use Api\User\Repository\UserAvatarRepository; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Laminas\Diactoros\UploadedFile; use Psr\Http\Message\UploadedFileInterface; use Ramsey\Uuid\Uuid; @@ -28,15 +28,13 @@ class UserAvatarService implements UserAvatarServiceInterface 'image/png' => 'png', ]; - /** - * @Inject({ - * UserAvatarRepository::class, - * "config" - * }) - */ + #[Inject( + UserAvatarRepository::class, + "config", + )] public function __construct( protected UserAvatarRepository $userAvatarRepository, - protected array $config + protected array $config, ) { } diff --git a/src/User/src/Service/UserRoleService.php b/src/User/src/Service/UserRoleService.php index 03bf223..112afc8 100644 --- a/src/User/src/Service/UserRoleService.php +++ b/src/User/src/Service/UserRoleService.php @@ -9,17 +9,15 @@ use Api\User\Collection\UserRoleCollection; use Api\User\Entity\UserRole; use Api\User\Repository\UserRoleRepository; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; class UserRoleService implements UserRoleServiceInterface { - /** - * @Inject({ - * UserRoleRepository::class - * }) - */ + #[Inject( + UserRoleRepository::class, + )] public function __construct( - protected UserRoleRepository $roleRepository + protected UserRoleRepository $roleRepository, ) { } diff --git a/src/User/src/Service/UserService.php b/src/User/src/Service/UserService.php index e54375b..b883f09 100644 --- a/src/User/src/Service/UserService.php +++ b/src/User/src/Service/UserService.php @@ -12,12 +12,12 @@ use Api\User\Collection\UserCollection; use Api\User\Entity\User; use Api\User\Entity\UserDetail; -use Api\User\Entity\UserResetPasswordEntity; +use Api\User\Entity\UserResetPassword; use Api\User\Entity\UserRole; use Api\User\Repository\UserDetailRepository; use Api\User\Repository\UserRepository; use Api\User\Repository\UserResetPasswordRepository; -use Dot\AnnotatedServices\Annotation\Inject; +use Dot\DependencyInjection\Attribute\Inject; use Dot\Mail\Exception\MailException; use Dot\Mail\Service\MailService; use Laminas\Log\LoggerInterface; @@ -29,20 +29,18 @@ class UserService implements UserServiceInterface { - /** - * @Inject({ - * UserRoleServiceInterface::class, - * MailService::class, - * TemplateRendererInterface::class, - * OAuthAccessTokenRepository::class, - * OAuthRefreshTokenRepository::class, - * UserRepository::class, - * UserDetailRepository::class, - * UserResetPasswordRepository::class, - * "dot-log.default_logger", - * "config" - * }) - */ + #[Inject( + UserRoleServiceInterface::class, + MailService::class, + TemplateRendererInterface::class, + OAuthAccessTokenRepository::class, + OAuthRefreshTokenRepository::class, + UserRepository::class, + UserDetailRepository::class, + UserResetPasswordRepository::class, + "dot-log.default_logger", + "config", + )] public function __construct( protected UserRoleServiceInterface $userRoleService, protected MailService $mailService, @@ -53,7 +51,7 @@ public function __construct( protected UserDetailRepository $userDetailRepository, protected UserResetPasswordRepository $userResetPasswordRepository, protected LoggerInterface $logger, - protected array $config = [] + protected array $config = [], ) { } @@ -190,10 +188,10 @@ public function emailExistsOther(string $email = '', string $uuid = ''): bool /** * @throws NotFoundException */ - public function findResetPasswordByHash(?string $hash): UserResetPasswordEntity + public function findResetPasswordByHash(?string $hash): UserResetPassword { $userResetPassword = $this->userResetPasswordRepository->findOneBy(['hash' => $hash]); - if (! $userResetPassword instanceof UserResetPasswordEntity) { + if (! $userResetPassword instanceof UserResetPassword) { throw new NotFoundException(sprintf(Message::RESET_PASSWORD_NOT_FOUND, (string) $hash)); } diff --git a/src/User/src/Service/UserServiceInterface.php b/src/User/src/Service/UserServiceInterface.php index 7f6244e..2c6a963 100644 --- a/src/User/src/Service/UserServiceInterface.php +++ b/src/User/src/Service/UserServiceInterface.php @@ -8,7 +8,7 @@ use Api\App\Exception\NotFoundException; use Api\User\Collection\UserCollection; use Api\User\Entity\User; -use Api\User\Entity\UserResetPasswordEntity; +use Api\User\Entity\UserResetPassword; use Dot\Mail\Exception\MailException; use RuntimeException; @@ -49,7 +49,7 @@ public function emailExistsOther(string $email = '', string $uuid = ''): bool; /** * @throws NotFoundException */ - public function findResetPasswordByHash(?string $hash): UserResetPasswordEntity; + public function findResetPasswordByHash(?string $hash): UserResetPassword; /** * @throws NotFoundException diff --git a/test/Functional/UserTest.php b/test/Functional/UserTest.php index dbab610..8886462 100644 --- a/test/Functional/UserTest.php +++ b/test/Functional/UserTest.php @@ -7,7 +7,7 @@ use Api\App\Message; use Api\User\Entity\User; use Api\User\Entity\UserAvatar; -use Api\User\Entity\UserResetPasswordEntity; +use Api\User\Entity\UserResetPassword; use Api\User\Service\UserAvatarService; use DateInterval; use DateTimeImmutable; @@ -311,9 +311,9 @@ public function testRequestResetPasswordExpired(): void { $user = $this->createUser(); - $resetPassword = (new UserResetPasswordEntity()) + $resetPassword = (new UserResetPassword()) ->setUser($user) - ->setStatus(UserResetPasswordEntity::STATUS_REQUESTED) + ->setStatus(UserResetPassword::STATUS_REQUESTED) ->setHash('test') ->setExpires((new DateTimeImmutable())->sub(new DateInterval('P1D'))); $user->addResetPassword($resetPassword); @@ -350,9 +350,9 @@ public function testRequestResetPasswordAlreadyUsed(): void { $user = $this->createUser(); - $resetPassword = (new UserResetPasswordEntity()) + $resetPassword = (new UserResetPassword()) ->setUser($user) - ->setStatus(UserResetPasswordEntity::STATUS_COMPLETED) + ->setStatus(UserResetPassword::STATUS_COMPLETED) ->setHash('test') ->setExpires((new DateTimeImmutable())->add(new DateInterval('P1D'))); $user->addResetPassword($resetPassword); @@ -389,9 +389,9 @@ public function testResetPassword(): void { $user = $this->createUser(); - $resetPassword = (new UserResetPasswordEntity()) + $resetPassword = (new UserResetPassword()) ->setUser($user) - ->setStatus(UserResetPasswordEntity::STATUS_REQUESTED) + ->setStatus(UserResetPassword::STATUS_REQUESTED) ->setHash('test') ->setExpires((new DateTimeImmutable())->add(new DateInterval('P1D'))); $user->addResetPassword($resetPassword); From 76e883e9fa997b931375114367ffd6faa59f1830 Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Mon, 10 Jun 2024 16:54:57 +0300 Subject: [PATCH 2/2] missing throws Signed-off-by: alexmerlin --- src/User/src/Handler/UserHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/User/src/Handler/UserHandler.php b/src/User/src/Handler/UserHandler.php index 88b50e8..cd8a190 100644 --- a/src/User/src/Handler/UserHandler.php +++ b/src/User/src/Handler/UserHandler.php @@ -89,6 +89,7 @@ public function patch(ServerRequestInterface $request): ResponseInterface * @throws BadRequestException * @throws ConflictException * @throws MailException + * @throws NotFoundException */ public function post(ServerRequestInterface $request): ResponseInterface {