Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from asgrim/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
DASPRiD committed Feb 25, 2016
2 parents 4571868 + d628305 commit b13861a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
7 changes: 5 additions & 2 deletions example/minimal-config.php
Expand Up @@ -3,18 +3,21 @@
'doctrine' => [
'connection' => [
'orm_default' => [
'url' => 'mysql://user:passeord@localhost/database',
'params' => [
'url' => 'mysql://user:password@localhost/database',
],
],
],
'driver' => [
'orm_default' => [
'class' => \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver::class,
'class' => \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain::class,
'drivers' => [
'My\Entity' => 'my_entity',
],
],
'my_entity' => [
'class' => \Doctrine\ORM\Mapping\Driver\XmlDriver::class,
'cache' => 'array',
'paths' => __DIR__ . '/doctrine',
],
],
Expand Down
31 changes: 30 additions & 1 deletion src/DriverFactory.php
Expand Up @@ -10,6 +10,7 @@
namespace ContainerInteropDoctrine;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver;
use Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator;
Expand All @@ -24,6 +25,11 @@
*/
class DriverFactory extends AbstractFactory
{
/**
* @var bool
*/
private static $isAnnotationLoaderRegistered = false;

/**
* {@inheritdoc}
*/
Expand All @@ -40,8 +46,13 @@ protected function createWithConfig(ContainerInterface $container, $configKey)
}

if (AnnotationDriver::class === $config['class'] || is_subclass_of($config['class'], AnnotationDriver::class)) {
$this->registerAnnotationLoader();

$driver = new $config['class'](
new CachedReader(new AnnotationReader(), $config['cache']),
new CachedReader(
new AnnotationReader(),
$this->retrieveDependency($container, $config['cache'], 'cache', CacheFactory::class)
),
$config['paths']
);
} else {
Expand Down Expand Up @@ -86,4 +97,22 @@ protected function getDefaultConfig($configKey)
'drivers' => [],
];
}

/**
* Registers the annotation loader
*/
private function registerAnnotationLoader()
{
if (self::$isAnnotationLoaderRegistered) {
return;
}

AnnotationRegistry::registerLoader(
function ($className) {
return class_exists($className);
}
);

self::$isAnnotationLoaderRegistered = true;
}
}
2 changes: 1 addition & 1 deletion src/EntityManagerFactory.php
Expand Up @@ -36,7 +36,7 @@ protected function createWithConfig(ContainerInterface $container, $configKey)
$container,
$config['connection'],
'connection',
ConfigurationFactory::class
ConnectionFactory::class
),
$this->retrieveDependency(
$container,
Expand Down

0 comments on commit b13861a

Please sign in to comment.