Commit 566fd3e2 authored by Avris's avatar Avris

v4.0

parent f7055b82
......@@ -4,7 +4,7 @@ Avris\Micrus\Doctrine\:
Avris\Micrus\Doctrine\Doctrine:
arguments:
$connection: '@config.database'
$proxyDir: '%PROJECT_DIR%/var/cache/{@env}/doctrine'
$proxyDir: '%CACHE_DIR%/doctrine'
$cache: '@?doctrineCache'
Avris\Micrus\Model\User\UserProviderInterface: Avris\Micrus\Doctrine\DoctrineUserProvider
......
......@@ -4,7 +4,7 @@ namespace Avris\Micrus\Doctrine;
use Avris\Bag\Bag;
use Avris\Micrus\Bootstrap\EventSubscriberInterface;
use Avris\Micrus\Bootstrap\ModuleInterface;
use Avris\Micrus\Console\ConsoleEvent;
use Avris\Micrus\Console\ConsoleWarmupEvent;
use Avris\Micrus\Tool\Config\ParametersProvider;
use Doctrine\Common\Cache\ClearableCache;
use Doctrine\Common\Proxy\Autoloader;
......@@ -41,10 +41,8 @@ class Doctrine implements ParametersProvider, EventSubscriberInterface
$this->entityManager = EntityManager::create($connection->all(), $config);
// TODO
$warmup = $this->onCacheWarmup();
if ($warmup) {
$logger->notice($warmup);
if ($warmupMessage = $this->warmupCache()) {
$logger->notice($warmupMessage);
}
}
......@@ -53,9 +51,7 @@ class Doctrine implements ParametersProvider, EventSubscriberInterface
return $this->entityManager;
}
// TODO re-think those three events
public function onCacheClear()
public function clearCache()
{
$config = $this->entityManager->getConfiguration();
......@@ -72,7 +68,7 @@ class Doctrine implements ParametersProvider, EventSubscriberInterface
}
}
public function onCacheWarmup()
public function warmupCache()
{
$proxyDir = $this->entityManager->getConfiguration()->getProxyDir();
......@@ -91,12 +87,8 @@ class Doctrine implements ParametersProvider, EventSubscriberInterface
);
}
public function onConsole(ConsoleEvent $event)
public function registerCommands(ConsoleWarmupEvent $event)
{
if (!$this->entityManager) {
return;
}
$proxyDir = $this->entityManager->getConfiguration()->getProxyDir();
Autoloader::register($proxyDir, 'DoctrineProxies');
......@@ -132,6 +124,8 @@ class Doctrine implements ParametersProvider, EventSubscriberInterface
public function getSubscribedEvents(): iterable
{
yield 'console' => [$this, 'onConsole'];
yield 'consoleWarmup' => [$this, 'registerCommands'];
yield 'cacheWarmup' => [$this, 'warmupCache'];
yield 'cacheClear' => [$this, 'clearCache'];
}
}
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