Skip to content

Commit

Permalink
register ORM annotations mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangut committed Apr 26, 2016
1 parent f29a75e commit c4e6f72
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
17 changes: 17 additions & 0 deletions src/DocumentManagerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down
25 changes: 23 additions & 2 deletions src/EntityManagerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
}

Expand Down
17 changes: 0 additions & 17 deletions src/ObjectManagerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit c4e6f72

Please sign in to comment.