Commit e71609b4 authored by Avris's avatar Avris

v4.0

parent 3cc85751
orm:
class: Avris\Micrus\Doctrine\Doctrine
params:
- '@logger'
- '@env'
- '@rootDir'
- '@config.parameters.?database'
- '#modelDirectory'
- '@?doctrineCache'
events: ['cacheClear', 'cacheWarmup', 'console']
tags: ['defaultParameters']
userProvider:
class: Avris\Micrus\Doctrine\DoctrineUserProvider
params: ['@orm']
......@@ -4,8 +4,6 @@ namespace Avris\Micrus\Doctrine;
use Avris\Micrus\Console\ConsoleEvent;
use Avris\Micrus\Model\ModelDirectory;
use Avris\Micrus\Model\ORM;
use Avris\Bag\Bag;
use Avris\Micrus\Tool\Logger;
use Avris\Micrus\Tool\Config\ParametersProvider;
use Doctrine\Common\Cache\ClearableCache;
use Doctrine\Common\Proxy\Autoloader;
......@@ -14,6 +12,7 @@ use Doctrine\ORM\Cache;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\ORM\Tools\Setup;
use Psr\Log\LoggerInterface;
class Doctrine implements ORM, ParametersProvider
{
......@@ -23,16 +22,7 @@ class Doctrine implements ORM, ParametersProvider
/** @var string */
protected $cacheDir;
/**
* @param Logger $logger
* @param string $env
* @param string $rootDir
* @param array $db
* @param ModelDirectory[] $modelDirectories
* @param Cache $cache
* @throws \Doctrine\ORM\ORMException
*/
public function __construct(Logger $logger, $env, $rootDir, $db, array $modelDirectories, Cache $cache = null)
public function __construct(LoggerInterface $logger, $env, $rootDir, $db, array $modelDirectories, Cache $cache = null)
{
if (empty($db)) {
$logger->warning('No ORM configuration');
......@@ -43,7 +33,7 @@ class Doctrine implements ORM, ParametersProvider
$this->cacheDir = $rootDir . '/var/cache/' . $env . '/doctrine'; // TODO inject
$dirs = [$rootDir . '/app/Model']; // TODO unify
$dirs = [$rootDir . '/src/Model']; // TODO unify
foreach ($modelDirectories as $dir) {
$dirs[] = $dir->getDirectory();
}
......@@ -60,7 +50,7 @@ class Doctrine implements ORM, ParametersProvider
$config->setSQLLogger(new DoctrineLogger($logger));
if (empty($db['charset'])) {
$db['charset'] = 'utf8';
$db['charset'] = 'utf8mb4';
}
$this->entityManager = EntityManager::create($db, $config);
......
<?php
namespace Avris\Micrus\Doctrine;
use Avris\Micrus\Tool\Logger;
use Doctrine\DBAL\Logging\SQLLogger;
use Psr\Log\LoggerInterface;
class DoctrineLogger implements SQLLogger
{
/** @var Logger */
/** @var LoggerInterface */
protected $logger;
public function __construct(Logger $logger)
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
......
<?php
namespace Avris\Micrus\Doctrine;
use Avris\Micrus\Bootstrap\Module;
use Avris\Micrus\Bootstrap\ModuleInterface;
use Avris\Micrus\Bootstrap\ModuleTrait;
class DoctrineModule implements Module
class DoctrineModule implements ModuleInterface
{
public function extendConfig($env, $rootDir)
{
return [
'services' => [
'orm' => [
'class' => Doctrine::class,
'params' => [
'@logger',
'@env',
'@rootDir',
'@config.parameters.?database',
'#modelDirectory',
'@?doctrineCache',
],
'events' => ['cacheClear', 'cacheWarmup', 'console'],
'tags' => ['defaultParameters'],
],
'userProvider' => [
'class' => DoctrineUserProvider::class,
'params' => ['@orm'],
],
],
];
}
use ModuleTrait;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment