Skip to content

Commit

Permalink
Merge pull request #309 from dotkernel/issue-308
Browse files Browse the repository at this point in the history
psr-container-doctrine 5.2.1 support and refactoring modules configuration
  • Loading branch information
arhimede authored Jul 12, 2024
2 parents 69699c9 + 8fa3e10 commit 31b99d6
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 30 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@
"mezzio/mezzio-problem-details": "^1.13.1",
"mezzio/mezzio-twigrenderer": "^2.15.0",
"ramsey/uuid-doctrine": "^2.1.0",
"roave/psr-container-doctrine": "^5.1.0",
"doctrine/orm": "^3.2",
"roave/psr-container-doctrine": "^5.2.1",
"symfony/filesystem": "^7.0.3"
},
"require-dev": {
Expand Down
25 changes: 3 additions & 22 deletions config/autoload/doctrine.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Api\App\Entity\EntityListenerResolver;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use Dot\Cache\Adapter\ArrayAdapter;
use Dot\Cache\Adapter\FilesystemAdapter;
Expand All @@ -22,28 +21,9 @@
],
],
'driver' => [
'orm_default' => [
'orm_default' => [
'class' => MappingDriverChain::class,
'drivers' => [
'Api\\User\\Entity' => 'UserEntities',
'Api\\Admin\\Entity' => 'AdminEntities',
'Api\\App\Entity' => 'AppEntities',
],
],
'AdminEntities' => [
'class' => AttributeDriver::class,
'cache' => 'array',
'paths' => __DIR__ . '/../../src/Admin/src/Entity',
],
'UserEntities' => [
'class' => AttributeDriver::class,
'cache' => 'array',
'paths' => __DIR__ . '/../../src/User/src/Entity',
],
'AppEntities' => [
'class' => AttributeDriver::class,
'cache' => 'array',
'paths' => __DIR__ . '/../../src/App/src/Entity',
'drivers' => [],
],
],
'types' => [
Expand All @@ -59,6 +39,7 @@
'metadata_cache' => 'filesystem',
'query_cache' => 'filesystem',
'hydration_cache' => 'array',
'typed_field_mapper' => null,
'second_level_cache' => [
'enabled' => true,
'default_lifetime' => 3600,
Expand Down
30 changes: 28 additions & 2 deletions src/Admin/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
use Api\Admin\Service\AdminService;
use Api\Admin\Service\AdminServiceInterface;
use Api\App\ConfigProvider as AppConfigProvider;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Dot\DependencyInjection\Factory\AttributedRepositoryFactory;
use Dot\DependencyInjection\Factory\AttributedServiceFactory;
use Mezzio\Application;
use Mezzio\Hal\Metadata\MetadataMap;

class ConfigProvider
Expand All @@ -30,14 +32,20 @@ public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
'doctrine' => $this->getDoctrineConfig(),
MetadataMap::class => $this->getHalConfig(),
];
}

public function getDependencies(): array
{
return [
'factories' => [
'delegators' => [
Application::class => [
RoutesDelegator::class,
],
],
'factories' => [
AdminHandler::class => AttributedServiceFactory::class,
AdminAccountHandler::class => AttributedServiceFactory::class,
AdminRoleHandler::class => AttributedServiceFactory::class,
Expand All @@ -47,13 +55,31 @@ public function getDependencies(): array
AdminRepository::class => AttributedRepositoryFactory::class,
AdminRoleRepository::class => AttributedRepositoryFactory::class,
],
'aliases' => [
'aliases' => [
AdminServiceInterface::class => AdminService::class,
AdminRoleServiceInterface::class => AdminRoleService::class,
],
];
}

private function getDoctrineConfig(): array
{
return [
'driver' => [
'orm_default' => [
'drivers' => [
'Api\Admin\Entity' => 'AdminEntities',
],
],
'AdminEntities' => [
'class' => AttributeDriver::class,
'cache' => 'array',
'paths' => __DIR__ . '/Entity',
],
],
];
}

public function getHalConfig(): array
{
return [
Expand Down
22 changes: 20 additions & 2 deletions src/App/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Api\App\Service\ErrorReportServiceInterface;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Dot\DependencyInjection\Factory\AttributedServiceFactory;
use Dot\Mail\Factory\MailOptionsAbstractFactory;
use Dot\Mail\Factory\MailServiceAbstractFactory;
Expand All @@ -47,6 +48,7 @@ public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
'doctrine' => $this->getDoctrineConfig(),
MetadataMap::class => $this->getHalConfig(),
];
}
Expand All @@ -57,8 +59,6 @@ public function getDependencies(): array
'delegators' => [
Application::class => [
RoutesDelegator::class,
\Api\Admin\RoutesDelegator::class,
\Api\User\RoutesDelegator::class,
],
],
'factories' => [
Expand Down Expand Up @@ -91,6 +91,24 @@ public function getDependencies(): array
];
}

private function getDoctrineConfig(): array
{
return [
'driver' => [
'orm_default' => [
'drivers' => [
'Api\App\Entity' => 'AppEntities',
],
],
'AppEntities' => [
'class' => AttributeDriver::class,
'cache' => 'array',
'paths' => __DIR__ . '/Entity',
],
],
];
}

public function getHalConfig(): array
{
return [];
Expand Down
30 changes: 28 additions & 2 deletions src/User/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
use Api\User\Service\UserRoleServiceInterface;
use Api\User\Service\UserService;
use Api\User\Service\UserServiceInterface;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Dot\DependencyInjection\Factory\AttributedRepositoryFactory;
use Dot\DependencyInjection\Factory\AttributedServiceFactory;
use Mezzio\Application;
use Mezzio\Hal\Metadata\MetadataMap;

class ConfigProvider
Expand All @@ -41,6 +43,7 @@ public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
'doctrine' => $this->getDoctrineConfig(),
MetadataMap::class => $this->getHalConfig(),
'templates' => $this->getTemplates(),
];
Expand All @@ -49,7 +52,12 @@ public function __invoke(): array
public function getDependencies(): array
{
return [
'factories' => [
'delegators' => [
Application::class => [
RoutesDelegator::class,
],
],
'factories' => [
AccountActivateHandler::class => AttributedServiceFactory::class,
AccountAvatarHandler::class => AttributedServiceFactory::class,
AccountHandler::class => AttributedServiceFactory::class,
Expand All @@ -69,14 +77,32 @@ public function getDependencies(): array
UserRoleRepository::class => AttributedRepositoryFactory::class,
UserAvatarRepository::class => AttributedRepositoryFactory::class,
],
'aliases' => [
'aliases' => [
UserAvatarServiceInterface::class => UserAvatarService::class,
UserRoleServiceInterface::class => UserRoleService::class,
UserServiceInterface::class => UserService::class,
],
];
}

private function getDoctrineConfig(): array
{
return [
'driver' => [
'orm_default' => [
'drivers' => [
'Api\User\Entity' => 'UserEntities',
],
],
'UserEntities' => [
'class' => AttributeDriver::class,
'cache' => 'array',
'paths' => __DIR__ . '/Entity',
],
],
];
}

public function getHalConfig(): array
{
return [
Expand Down

0 comments on commit 31b99d6

Please sign in to comment.