Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EntityManager decorator #22

Merged
merged 8 commits into from Nov 2, 2018
Copy path View file
@@ -4,12 +4,12 @@
use Doctrine\DBAL\Connection;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager as DoctrineEntityManager;
use Doctrine\ORM\Mapping\UnderscoreNamingStrategy;
use Nette\DI\CompilerExtension;
use Nette\DI\Helpers;
use Nette\DI\Statement;
use Nettrine\ORM\EntityManager;
use Nettrine\ORM\EntityManagerFactory;
use Nettrine\ORM\EntityManagerDecorator;
use Nettrine\ORM\Exception\Logical\InvalidStateException;
use Nettrine\ORM\ManagerRegistry;
use Nettrine\ORM\Mapping\ContainerEntityListenerResolver;
@@ -19,7 +19,7 @@ final class OrmExtension extends CompilerExtension
/** @var mixed[] */
private $defaults = [
'entityManagerClass' => EntityManager::class,
'entityManagerDecoratorClass' => EntityManagerDecorator::class,
'configuration' => [
'proxyDir' => '%tempDir%/proxies',
'autoGenerateProxyClasses' => null,
@@ -115,26 +115,30 @@ public function loadEntityManagerConfiguration(): void
$builder = $this->getContainerBuilder();
$config = $this->getConfig();
$entityManagerClass = $config['entityManagerClass'];
if (!class_exists($entityManagerClass)) {
throw new InvalidStateException(sprintf('EntityManager class "%s" not found', $entityManagerClass));
$entityManagerDecoratorClass = $config['entityManagerDecoratorClass'];
if (!class_exists($entityManagerDecoratorClass)) {
throw new InvalidStateException(sprintf('EntityManagerDecorator class "%s" not found', $entityManagerDecoratorClass));
}
// Entity Manager
$builder->addDefinition($this->prefix('entityManager'))
->setType($entityManagerClass)
->setFactory(EntityManagerFactory::class . '::create', [
$original = $builder->addDefinition($this->prefix('entityManager'))

This comment has been minimized.

Copy link
@f3l1x

f3l1x Jun 15, 2018

Member

Could we drop entityManager, right?

This comment has been minimized.

Copy link
@f3l1x

f3l1x Jun 15, 2018

Member

Oh I see.

This comment has been minimized.

Copy link
@f3l1x

f3l1x Jun 15, 2018

Member

It's needed for decorator.

->setType(DoctrineEntityManager::class)
->setFactory(DoctrineEntityManager::class . '::create', [
$builder->getDefinitionByType(Connection::class), // Nettrine/DBAL
$this->prefix('@configuration'),
$entityManagerClass,
]);
])
->setAutowired(false);
// Entity Manager Decorator
$builder->addDefinition($this->prefix('entityManagerDecorator'))
->setFactory($entityManagerDecoratorClass, [$original]);
// ManagerRegistry
$builder->addDefinition($this->prefix('managerRegistry'))
->setType(ManagerRegistry::class)
->setArguments([
$builder->getDefinitionByType(Connection::class),
$this->prefix('@entityManager'),
$this->prefix('@entityManagerDecorator'),
]);
}
Copy path View file

This file was deleted.

Oops, something went wrong.
Copy path View file
@@ -0,0 +1,10 @@
<?php declare(strict_types = 1);
namespace Nettrine\ORM;
use Doctrine\ORM\Decorator\EntityManagerDecorator as DoctrineEntityManagerDecorator;
class EntityManagerDecorator extends DoctrineEntityManagerDecorator
{
}
Copy path View file

This file was deleted.

Oops, something went wrong.
Copy path View file
@@ -4,7 +4,7 @@
use Doctrine\Common\Persistence\AbstractManagerRegistry;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\Proxy\Proxy;
use Nette\DI\Container;
@@ -15,7 +15,7 @@ class ManagerRegistry extends AbstractManagerRegistry
/** @var Container */
private $container;
public function __construct(Connection $connection, EntityManager $em, Container $container)
public function __construct(Connection $connection, EntityManagerInterface $em, Container $container)
{
$defaultConnection = $container->findByType(get_class($connection))[0];
$defaultManager = $container->findByType(get_class($em))[0];
@@ -55,7 +55,7 @@ public function getAliasNamespace($alias): string
{
foreach (array_keys($this->getManagers()) as $name) {
try {
/** @var EntityManager $entityManager */
/** @var EntityManagerInterface $entityManager */
$entityManager = $this->getManager($name);
return $entityManager->getConfiguration()->getEntityNamespace($alias);
} catch (ORMException $e) {
@@ -10,7 +10,7 @@
use Nettrine\ORM\DI\OrmAnnotationsExtension;
use Nettrine\ORM\DI\OrmCacheExtension;
use Nettrine\ORM\DI\OrmExtension;
use Nettrine\ORM\EntityManager;
use Nettrine\ORM\EntityManagerDecorator;
use Tests\Nettrine\ORM\Cases\TestCase;
final class OrmCacheExtensionTest extends TestCase
@@ -34,8 +34,8 @@ public function testCacheDrivers(): void
/** @var Container $container */
$container = new $class();
/** @var EntityManager $em */
$em = $container->getByType(EntityManager::class);
/** @var EntityManagerDecorator $em */
$em = $container->getByType(EntityManagerDecorator::class);
self::assertInstanceOf(FilesystemCache::class, $em->getConfiguration()->getHydrationCacheImpl());
self::assertInstanceOf(FilesystemCache::class, $em->getConfiguration()->getMetadataCacheImpl());
@@ -8,7 +8,7 @@
use Nettrine\DBAL\DI\DbalExtension;
use Nettrine\ORM\DI\OrmAnnotationsExtension;
use Nettrine\ORM\DI\OrmExtension;
use Nettrine\ORM\EntityManager;
use Nettrine\ORM\EntityManagerDecorator;
use Tests\Nettrine\ORM\Cases\TestCase;
use Tests\Nettrine\ORM\Fixtures\DummyEntityManager;
@@ -24,7 +24,7 @@ public function testRegisterAnnotations(): void
/** @var Container $container */
$container = new $class();
self::assertInstanceOf(EntityManager::class, $container->getByType(EntityManager::class));
self::assertInstanceOf(EntityManagerDecorator::class, $container->getByType(EntityManagerDecorator::class));
}
public function testOwnEntityManager(): void
@@ -34,7 +34,7 @@ public function testOwnEntityManager(): void
self::setUpCompiler($compiler);
$compiler->addConfig([
'orm' => [
'entityManagerClass' => DummyEntityManager::class,
'entityManagerDecoratorClass' => DummyEntityManager::class,
],
]);
}, 'b');
@@ -2,9 +2,9 @@
namespace Tests\Nettrine\ORM\Fixtures;
use Nettrine\ORM\EntityManager;
use Nettrine\ORM\EntityManagerDecorator;
class DummyEntityManager extends EntityManager
class DummyEntityManager extends EntityManagerDecorator

This comment has been minimized.

Copy link
@f3l1x

f3l1x Jun 18, 2018

Member

DummyEntityManagerDecorator

{
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.