diff --git a/src/DocumentManagerBuilder.php b/src/DocumentManagerBuilder.php index 81ebce4..f9c9d1a 100644 --- a/src/DocumentManagerBuilder.php +++ b/src/DocumentManagerBuilder.php @@ -10,6 +10,7 @@ namespace Jgut\Slim\Doctrine; use Doctrine\Common\Annotations\AnnotationReader; +use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain; use Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver; use Doctrine\Common\Proxy\AbstractProxyFactory; use Doctrine\MongoDB\Connection; @@ -106,6 +107,22 @@ protected static function getConfiguration(array $options) return $config; } + /** + * Create Doctrine ODM configuration. + * + * @param \Doctrine\ODM\MongoDB\Configuration $config + * @param array $options + * + * @throws \RuntimeException + */ + protected static function setupMetadataDriver(Configuration $config, array $options) + { + $metadataDriver = new MappingDriverChain; + $metadataDriver->setDefaultDriver(self::getMetadataDriver($options)); + + $config->setMetadataDriverImpl($metadataDriver); + } + /** * @param array $options * diff --git a/src/EntityManagerBuilder.php b/src/EntityManagerBuilder.php index 06198f0..05ca16b 100644 --- a/src/EntityManagerBuilder.php +++ b/src/EntityManagerBuilder.php @@ -10,6 +10,7 @@ namespace Jgut\Slim\Doctrine; use Doctrine\Common\Annotations\AnnotationReader; +use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain; use Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver; use Doctrine\Common\Proxy\AbstractProxyFactory; use Doctrine\DBAL\Connection; @@ -123,15 +124,35 @@ protected static function getConfiguration(array $options) } /** - * @param array $options + * Create Doctrine ODM configuration. + * + * @param \Doctrine\ORM\Configuration $config + * @param array $options + * + * @throws \RuntimeException + */ + protected static function setupMetadataDriver(Configuration $config, array $options) + { + $metadataDriver = new MappingDriverChain; + $metadataDriver->setDefaultDriver(self::getMetadataDriver($config, $options)); + + $config->setMetadataDriverImpl($metadataDriver); + } + + /** + * @param \Doctrine\ORM\Configuration $config + * @param array $options * * @throws \RuntimeException * * @return \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver */ - protected static function getMetadataDriver(array $options) + protected static function getMetadataDriver(Configuration $config, array $options) { if ($options['annotation_paths']) { + // Only to register ORM annotations mapping + $config->newDefaultAnnotationDriver(); + return new AnnotationDriver(new AnnotationReader, (array) $options['annotation_paths']); } diff --git a/src/ObjectManagerTrait.php b/src/ObjectManagerTrait.php index 858d5cf..2a20f13 100644 --- a/src/ObjectManagerTrait.php +++ b/src/ObjectManagerTrait.php @@ -16,7 +16,6 @@ use Doctrine\Common\Cache\MemcacheCache; use Doctrine\Common\Cache\RedisCache; use Doctrine\Common\Cache\XcacheCache; -use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain; /** * Doctrine Object Manager commons. @@ -86,22 +85,6 @@ protected static function setupAnnotationMetadata(array $options) } } - /** - * Create Doctrine ODM configuration. - * - * @param \Doctrine\ORM\Configuration|\Doctrine\ODM\MongoDB\Configuration $config - * @param array $options - * - * @throws \RuntimeException - */ - protected static function setupMetadataDriver($config, array $options) - { - $metadataDriver = new MappingDriverChain; - $metadataDriver->setDefaultDriver(self::getMetadataDriver($options)); - - $config->setMetadataDriverImpl($metadataDriver); - } - /** * Setup proxies. *