Skip to content

Commit 31b99d6

Browse files
authored
Merge pull request #309 from dotkernel/issue-308
psr-container-doctrine 5.2.1 support and refactoring modules configuration
2 parents 69699c9 + 8fa3e10 commit 31b99d6

5 files changed

Lines changed: 80 additions & 30 deletions

File tree

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@
7777
"mezzio/mezzio-problem-details": "^1.13.1",
7878
"mezzio/mezzio-twigrenderer": "^2.15.0",
7979
"ramsey/uuid-doctrine": "^2.1.0",
80-
"roave/psr-container-doctrine": "^5.1.0",
81-
"doctrine/orm": "^3.2",
80+
"roave/psr-container-doctrine": "^5.2.1",
8281
"symfony/filesystem": "^7.0.3"
8382
},
8483
"require-dev": {

config/autoload/doctrine.global.php

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
declare(strict_types=1);
44

55
use Api\App\Entity\EntityListenerResolver;
6-
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
76
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
87
use Dot\Cache\Adapter\ArrayAdapter;
98
use Dot\Cache\Adapter\FilesystemAdapter;
@@ -22,28 +21,9 @@
2221
],
2322
],
2423
'driver' => [
25-
'orm_default' => [
24+
'orm_default' => [
2625
'class' => MappingDriverChain::class,
27-
'drivers' => [
28-
'Api\\User\\Entity' => 'UserEntities',
29-
'Api\\Admin\\Entity' => 'AdminEntities',
30-
'Api\\App\Entity' => 'AppEntities',
31-
],
32-
],
33-
'AdminEntities' => [
34-
'class' => AttributeDriver::class,
35-
'cache' => 'array',
36-
'paths' => __DIR__ . '/../../src/Admin/src/Entity',
37-
],
38-
'UserEntities' => [
39-
'class' => AttributeDriver::class,
40-
'cache' => 'array',
41-
'paths' => __DIR__ . '/../../src/User/src/Entity',
42-
],
43-
'AppEntities' => [
44-
'class' => AttributeDriver::class,
45-
'cache' => 'array',
46-
'paths' => __DIR__ . '/../../src/App/src/Entity',
26+
'drivers' => [],
4727
],
4828
],
4929
'types' => [
@@ -59,6 +39,7 @@
5939
'metadata_cache' => 'filesystem',
6040
'query_cache' => 'filesystem',
6141
'hydration_cache' => 'array',
42+
'typed_field_mapper' => null,
6243
'second_level_cache' => [
6344
'enabled' => true,
6445
'default_lifetime' => 3600,

src/Admin/src/ConfigProvider.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
use Api\Admin\Service\AdminService;
2121
use Api\Admin\Service\AdminServiceInterface;
2222
use Api\App\ConfigProvider as AppConfigProvider;
23+
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
2324
use Dot\DependencyInjection\Factory\AttributedRepositoryFactory;
2425
use Dot\DependencyInjection\Factory\AttributedServiceFactory;
26+
use Mezzio\Application;
2527
use Mezzio\Hal\Metadata\MetadataMap;
2628

2729
class ConfigProvider
@@ -30,14 +32,20 @@ public function __invoke(): array
3032
{
3133
return [
3234
'dependencies' => $this->getDependencies(),
35+
'doctrine' => $this->getDoctrineConfig(),
3336
MetadataMap::class => $this->getHalConfig(),
3437
];
3538
}
3639

3740
public function getDependencies(): array
3841
{
3942
return [
40-
'factories' => [
43+
'delegators' => [
44+
Application::class => [
45+
RoutesDelegator::class,
46+
],
47+
],
48+
'factories' => [
4149
AdminHandler::class => AttributedServiceFactory::class,
4250
AdminAccountHandler::class => AttributedServiceFactory::class,
4351
AdminRoleHandler::class => AttributedServiceFactory::class,
@@ -47,13 +55,31 @@ public function getDependencies(): array
4755
AdminRepository::class => AttributedRepositoryFactory::class,
4856
AdminRoleRepository::class => AttributedRepositoryFactory::class,
4957
],
50-
'aliases' => [
58+
'aliases' => [
5159
AdminServiceInterface::class => AdminService::class,
5260
AdminRoleServiceInterface::class => AdminRoleService::class,
5361
],
5462
];
5563
}
5664

65+
private function getDoctrineConfig(): array
66+
{
67+
return [
68+
'driver' => [
69+
'orm_default' => [
70+
'drivers' => [
71+
'Api\Admin\Entity' => 'AdminEntities',
72+
],
73+
],
74+
'AdminEntities' => [
75+
'class' => AttributeDriver::class,
76+
'cache' => 'array',
77+
'paths' => __DIR__ . '/Entity',
78+
],
79+
],
80+
];
81+
}
82+
5783
public function getHalConfig(): array
5884
{
5985
return [

src/App/src/ConfigProvider.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Api\App\Service\ErrorReportServiceInterface;
2323
use Doctrine\ORM\EntityManager;
2424
use Doctrine\ORM\EntityManagerInterface;
25+
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
2526
use Dot\DependencyInjection\Factory\AttributedServiceFactory;
2627
use Dot\Mail\Factory\MailOptionsAbstractFactory;
2728
use Dot\Mail\Factory\MailServiceAbstractFactory;
@@ -47,6 +48,7 @@ public function __invoke(): array
4748
{
4849
return [
4950
'dependencies' => $this->getDependencies(),
51+
'doctrine' => $this->getDoctrineConfig(),
5052
MetadataMap::class => $this->getHalConfig(),
5153
];
5254
}
@@ -57,8 +59,6 @@ public function getDependencies(): array
5759
'delegators' => [
5860
Application::class => [
5961
RoutesDelegator::class,
60-
\Api\Admin\RoutesDelegator::class,
61-
\Api\User\RoutesDelegator::class,
6262
],
6363
],
6464
'factories' => [
@@ -91,6 +91,24 @@ public function getDependencies(): array
9191
];
9292
}
9393

94+
private function getDoctrineConfig(): array
95+
{
96+
return [
97+
'driver' => [
98+
'orm_default' => [
99+
'drivers' => [
100+
'Api\App\Entity' => 'AppEntities',
101+
],
102+
],
103+
'AppEntities' => [
104+
'class' => AttributeDriver::class,
105+
'cache' => 'array',
106+
'paths' => __DIR__ . '/Entity',
107+
],
108+
],
109+
];
110+
}
111+
94112
public function getHalConfig(): array
95113
{
96114
return [];

src/User/src/ConfigProvider.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
use Api\User\Service\UserRoleServiceInterface;
3232
use Api\User\Service\UserService;
3333
use Api\User\Service\UserServiceInterface;
34+
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
3435
use Dot\DependencyInjection\Factory\AttributedRepositoryFactory;
3536
use Dot\DependencyInjection\Factory\AttributedServiceFactory;
37+
use Mezzio\Application;
3638
use Mezzio\Hal\Metadata\MetadataMap;
3739

3840
class ConfigProvider
@@ -41,6 +43,7 @@ public function __invoke(): array
4143
{
4244
return [
4345
'dependencies' => $this->getDependencies(),
46+
'doctrine' => $this->getDoctrineConfig(),
4447
MetadataMap::class => $this->getHalConfig(),
4548
'templates' => $this->getTemplates(),
4649
];
@@ -49,7 +52,12 @@ public function __invoke(): array
4952
public function getDependencies(): array
5053
{
5154
return [
52-
'factories' => [
55+
'delegators' => [
56+
Application::class => [
57+
RoutesDelegator::class,
58+
],
59+
],
60+
'factories' => [
5361
AccountActivateHandler::class => AttributedServiceFactory::class,
5462
AccountAvatarHandler::class => AttributedServiceFactory::class,
5563
AccountHandler::class => AttributedServiceFactory::class,
@@ -69,14 +77,32 @@ public function getDependencies(): array
6977
UserRoleRepository::class => AttributedRepositoryFactory::class,
7078
UserAvatarRepository::class => AttributedRepositoryFactory::class,
7179
],
72-
'aliases' => [
80+
'aliases' => [
7381
UserAvatarServiceInterface::class => UserAvatarService::class,
7482
UserRoleServiceInterface::class => UserRoleService::class,
7583
UserServiceInterface::class => UserService::class,
7684
],
7785
];
7886
}
7987

88+
private function getDoctrineConfig(): array
89+
{
90+
return [
91+
'driver' => [
92+
'orm_default' => [
93+
'drivers' => [
94+
'Api\User\Entity' => 'UserEntities',
95+
],
96+
],
97+
'UserEntities' => [
98+
'class' => AttributeDriver::class,
99+
'cache' => 'array',
100+
'paths' => __DIR__ . '/Entity',
101+
],
102+
],
103+
];
104+
}
105+
80106
public function getHalConfig(): array
81107
{
82108
return [

0 commit comments

Comments
 (0)