2024-06-30 20:29:50 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace GamesShop;
|
|
|
|
|
|
|
|
use Doctrine\DBAL\Connection;
|
|
|
|
use Doctrine\DBAL\DriverManager;
|
|
|
|
use Doctrine\ORM\EntityManager;
|
2024-07-05 20:29:35 +00:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2024-06-30 20:29:50 +00:00
|
|
|
use Doctrine\ORM\ORMSetup;
|
|
|
|
use GamesShop\Environment\EnvironmentHandler;
|
|
|
|
|
|
|
|
final class DoctrineManager
|
|
|
|
{
|
|
|
|
public function setup() {
|
|
|
|
$container = ContainerHandler::getInstance();
|
|
|
|
|
|
|
|
$environmentHandler = $container->get(EnvironmentHandler::class);
|
|
|
|
|
|
|
|
$config = ORMSetup::createAttributeMetadataConfiguration(
|
|
|
|
paths: [ Paths::PHP_SOURCE_PATH . '/Entities' ],
|
|
|
|
isDevMode: !$environmentHandler->isProduction()
|
|
|
|
);
|
|
|
|
|
|
|
|
$dbEnvironment = $environmentHandler->getDatabaseEnvironment();
|
|
|
|
$connection = DriverManager::getConnection($dbEnvironment->getDoctrineConfig());
|
|
|
|
|
|
|
|
$entityManager = new EntityManager($connection, $config);
|
|
|
|
|
|
|
|
$container->addShared(EntityManager::class, $entityManager);
|
2024-07-05 20:29:35 +00:00
|
|
|
$container->addShared(EntityManagerInterface::class, $entityManager);
|
2024-06-30 20:29:50 +00:00
|
|
|
$container->addShared(Connection::class, $connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|