Skip to content

Commit 3ef4137

Browse files
committed
Issue #394: Service refactoring
Signed-off-by: alexmerlin <[email protected]>
1 parent 2d67f51 commit 3ef4137

File tree

146 files changed

+1647
-1851
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+1647
-1851
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
"Api\\User\\": "src/User/src/",
9898
"Core\\Admin\\": "src/Core/src/Admin/src/",
9999
"Core\\App\\": "src/Core/src/App/src/",
100+
"Core\\Security\\": "src/Core/src/Security/src/",
100101
"Core\\User\\": "src/Core/src/User/src/"
101102
}
102103
},

config/autoload/cors.local.php.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ return [
1111
* Leaving this line here makes your application accessible by any origin.
1212
*
1313
* To restrict, replace this line with a list of origins that should have access to your application.
14-
* Example: "domain1.com", "domain2.com"
14+
* Example: 'domain1.com', 'domain2.com'
1515
*/
1616
ConfigurationInterface::ANY_ORIGIN,
1717
],

config/autoload/dependencies.global.php

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,53 @@
33
declare(strict_types=1);
44

55
use Api\App\Factory\ErrorResponseGeneratorFactory;
6-
use Api\App\Factory\OAuthAccessTokenRepositoryFactory;
7-
use Api\App\Factory\OAuthAuthCodeRepositoryFactory;
8-
use Api\App\Factory\OAuthClientRepositoryFactory;
9-
use Api\App\Factory\OAuthRefreshTokenRepositoryFactory;
10-
use Api\App\Factory\OAuthScopeRepositoryFactory;
116
use Api\App\Factory\UserIdentityFactory;
12-
use Api\App\Factory\UserRepositoryFactory;
13-
use Core\App\Repository\OAuthAccessTokenRepository;
14-
use Core\App\Repository\OAuthAuthCodeRepository;
15-
use Core\App\Repository\OAuthClientRepository;
16-
use Core\App\Repository\OAuthRefreshTokenRepository;
17-
use Core\App\Repository\OAuthScopeRepository;
7+
use Core\Security\Repository\OAuthAccessTokenRepository;
8+
use Core\Security\Repository\OAuthAuthCodeRepository;
9+
use Core\Security\Repository\OAuthClientRepository;
10+
use Core\Security\Repository\OAuthRefreshTokenRepository;
11+
use Core\Security\Repository\OAuthScopeRepository;
1812
use Core\User\Repository\UserRepository;
1913
use Core\User\UserIdentity;
2014
use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand;
21-
use Dot\ErrorHandler\ErrorHandlerInterface;
22-
use Dot\ErrorHandler\LogErrorHandler;
2315
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
2416
use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface;
2517
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
2618
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
2719
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
2820
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
21+
use Mezzio\Authentication\UserInterface;
22+
use Mezzio\Authorization\AuthorizationInterface;
23+
use Mezzio\Authorization\Rbac\LaminasRbac;
24+
use Mezzio\Middleware\ErrorResponseGenerator;
2925
use Roave\PsrContainerDoctrine\Migrations\CommandFactory;
3026

3127
return [
3228
// Provides application-wide services.
33-
// We recommend using fully-qualified class names whenever possible as
34-
// service names.
29+
// We recommend using fully-qualified class names whenever possible as service names.
3530
'dependencies' => [
36-
// Use 'aliases' to alias a service name to another service. The
37-
// key is the alias name, the value is the service to which it points.
31+
// Use 'aliases' to alias a service name to another service.
32+
// The key is the alias name, the value is the service to which it points.
3833
'aliases' => [
39-
AccessTokenRepositoryInterface::class => OAuthAccessTokenRepository::class,
40-
AuthCodeRepositoryInterface::class => OAuthAuthCodeRepository::class,
41-
ClientRepositoryInterface::class => OAuthClientRepository::class,
42-
RefreshTokenRepositoryInterface::class => OAuthRefreshTokenRepository::class,
43-
ScopeRepositoryInterface::class => OAuthScopeRepository::class,
44-
Mezzio\Authentication\UserInterface::class => UserIdentity::class,
45-
ErrorHandlerInterface::class => LogErrorHandler::class,
46-
Mezzio\Authorization\AuthorizationInterface::class => Mezzio\Authorization\Rbac\LaminasRbac::class,
47-
UserRepositoryInterface::class => UserRepository::class,
34+
AccessTokenRepositoryInterface::class => OAuthAccessTokenRepository::class,
35+
AuthCodeRepositoryInterface::class => OAuthAuthCodeRepository::class,
36+
ClientRepositoryInterface::class => OAuthClientRepository::class,
37+
UserInterface::class => UserIdentity::class,
38+
AuthorizationInterface::class => LaminasRbac::class,
39+
RefreshTokenRepositoryInterface::class => OAuthRefreshTokenRepository::class,
40+
ScopeRepositoryInterface::class => OAuthScopeRepository::class,
41+
UserRepositoryInterface::class => UserRepository::class,
4842
],
49-
// Use 'invokables' for constructor-less services, or services that do
50-
// not require arguments to the constructor. Map a service name to the
51-
// class name.
43+
// Use 'invokables' for constructor-less services, or services that do not require arguments to the constructor.
44+
// Map a service name to the class name.
5245
'invokables' => [
5346
// Fully\Qualified\InterfaceName::class => Fully\Qualified\ClassName::class,
5447
],
5548
// Use 'factories' for services provided by callbacks/factory classes.
5649
'factories' => [
57-
ExecuteCommand::class => CommandFactory::class,
58-
Mezzio\Middleware\ErrorResponseGenerator::class => ErrorResponseGeneratorFactory::class,
59-
OAuthAccessTokenRepository::class => OAuthAccessTokenRepositoryFactory::class,
60-
OAuthAuthCodeRepository::class => OAuthAuthCodeRepositoryFactory::class,
61-
OAuthClientRepository::class => OAuthClientRepositoryFactory::class,
62-
OAuthRefreshTokenRepository::class => OAuthRefreshTokenRepositoryFactory::class,
63-
OAuthScopeRepository::class => OAuthScopeRepositoryFactory::class,
64-
UserRepository::class => UserRepositoryFactory::class,
65-
UserIdentity::class => UserIdentityFactory::class,
50+
ExecuteCommand::class => CommandFactory::class,
51+
ErrorResponseGenerator::class => ErrorResponseGeneratorFactory::class,
52+
UserIdentity::class => UserIdentityFactory::class,
6653
],
6754
],
6855
];

config/autoload/mezzio-tooling-factories.global.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

config/autoload/templates.global.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
'globals' => [],
1818
'optimizations' => -1,
1919
'runtime_loaders' => [],
20-
// 'timezone' => '',
20+
'timezone' => 'UTC',
2121
],
2222
];

config/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class_exists(Mezzio\Tooling\ConfigProvider::class)
5151
// Default App module config
5252
Core\Admin\ConfigProvider::class,
5353
Core\App\ConfigProvider::class,
54+
Core\Security\ConfigProvider::class,
5455
Core\User\ConfigProvider::class,
5556
Api\Admin\ConfigProvider::class,
5657
Api\App\ConfigProvider::class,

documentation/command/admin-create.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ after replacing:
2323
2424
If the submitted data is valid, the outputted response is:
2525

26-
```text
27-
Admin account has been created.
28-
```
26+
>
27+
> [INFO] Admin account has been created.
28+
>
2929
3030
The new admin account is ready to use.
3131

documentation/command/token-generate.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ The output should look similar to this:
3636
Error reporting token:
3737
3838
0123456789abcdef0123456789abcdef01234567
39+
40+
* copy the generated token
41+
* open config/autoload/error-handling.global.php
42+
* paste the copied string inside the tokens array found under the ErrorReportServiceInterface::class key.
3943
```
4044

4145
Copy the generated token.

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ includes:
44
parameters:
55
level: 5
66
paths:
7+
- bin
8+
- config
9+
- public
710
- src
811
- test
912
treatPhpDocTypesAsCertain: false

src/Admin/src/Command/AdminCreateCommand.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
namespace Api\Admin\Command;
66

77
use Api\Admin\InputFilter\CreateAdminInputFilter;
8-
use Api\Admin\Service\AdminRoleService;
9-
use Api\Admin\Service\AdminService;
10-
use Api\App\Exception\BadRequestException;
11-
use Api\App\Exception\ConflictException;
12-
use Api\App\Exception\NotFoundException;
138
use Core\Admin\Entity\AdminRole;
9+
use Core\Admin\Service\AdminRoleServiceInterface;
10+
use Core\Admin\Service\AdminServiceInterface;
11+
use Core\App\Exception\BadRequestException;
12+
use Core\App\Exception\ConflictException;
13+
use Core\App\Exception\NotFoundException;
1414
use Core\App\Message;
15+
use Dot\DependencyInjection\Attribute\Inject;
1516
use Symfony\Component\Console\Attribute\AsCommand;
1617
use Symfony\Component\Console\Command\Command;
1718
use Symfony\Component\Console\Input\InputInterface;
1819
use Symfony\Component\Console\Input\InputOption;
1920
use Symfony\Component\Console\Output\OutputInterface;
21+
use Symfony\Component\Console\Style\SymfonyStyle;
2022

2123
use function implode;
2224
use function sprintf;
@@ -32,9 +34,13 @@ class AdminCreateCommand extends Command
3234
/** @var string $defaultName */
3335
protected static $defaultName = 'admin:create';
3436

37+
#[Inject(
38+
AdminServiceInterface::class,
39+
AdminRoleServiceInterface::class,
40+
)]
3541
public function __construct(
36-
protected AdminService $adminService,
37-
protected AdminRoleService $adminRoleService,
42+
protected AdminServiceInterface $adminService,
43+
protected AdminRoleServiceInterface $adminRoleService,
3844
) {
3945
parent::__construct(self::$defaultName);
4046
}
@@ -74,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7480

7581
$this->adminService->createAdmin($inputFilter->getValues());
7682

77-
$output->writeln(Message::ADMIN_CREATED);
83+
(new SymfonyStyle($input, $output))->info(Message::ADMIN_CREATED);
7884

7985
return Command::SUCCESS;
8086
}
@@ -84,7 +90,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8490
*/
8591
private function getData(InputInterface $input): array
8692
{
87-
$role = $this->adminRoleService->findOneBy(['name' => AdminRole::ROLE_ADMIN]);
93+
$adminRole = $this->adminRoleService->getAdminRoleRepository()->findOneBy(['name' => AdminRole::ROLE_ADMIN]);
94+
if (! $adminRole instanceof AdminRole) {
95+
throw new NotFoundException(Message::ROLE_NOT_FOUND);
96+
}
8897

8998
return [
9099
'identity' => $input->getOption('identity'),
@@ -93,7 +102,7 @@ private function getData(InputInterface $input): array
93102
'firstName' => $input->getOption('firstName'),
94103
'lastName' => $input->getOption('lastName'),
95104
'roles' => [
96-
['uuid' => $role->getUuid()->toString()],
105+
['uuid' => $adminRole->getUuid()->toString()],
97106
],
98107
];
99108
}

0 commit comments

Comments
 (0)