-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use DoctrineCacheBundle to create cache drivers
- Loading branch information
1 parent
df57980
commit e37301f
Showing
7 changed files
with
109 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,19 +23,43 @@ | |
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension; | ||
use Symfony\Component\Config\FileLocator; | ||
use Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\SymfonyBridgeAdapter; | ||
use Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\CacheProviderLoader; | ||
|
||
/** | ||
* DoctrineExtension is an extension for the Doctrine DBAL and ORM library. | ||
* | ||
* @author Jonathan H. Wage <[email protected]> | ||
* @author Fabien Potencier <[email protected]> | ||
* @author Benjamin Eberlei <[email protected]> | ||
* @author Fabio B. Silva <[email protected]> | ||
* @author Kinn Coelho Julião <[email protected]> | ||
*/ | ||
class DoctrineExtension extends AbstractDoctrineExtension | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $defaultConnection; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $entityManagers; | ||
|
||
/** | ||
* @var \Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\CacheProviderLoader | ||
*/ | ||
private $adapter; | ||
|
||
/** | ||
* @param \Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\SymfonyBridgeAdapter $adapter | ||
*/ | ||
public function __construct(SymfonyBridgeAdapter $adapter = null) | ||
{ | ||
$this->adapter = $adapter ?: new SymfonyBridgeAdapter(new CacheProviderLoader(), 'doctrine.orm', 'orm'); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
|
@@ -44,6 +68,8 @@ public function load(array $configs, ContainerBuilder $container) | |
$configuration = $this->getConfiguration($configs, $container); | ||
$config = $this->processConfiguration($configuration, $configs); | ||
|
||
$this->adapter->loadServicesConfiguration($container); | ||
|
||
if (!empty($config['dbal'])) { | ||
$this->dbalLoad($config['dbal'], $container); | ||
} | ||
|
@@ -84,6 +110,7 @@ protected function dbalLoad(array $config, ContainerBuilder $container) | |
$keys = array_keys($config['connections']); | ||
$config['default_connection'] = reset($keys); | ||
} | ||
|
||
$this->defaultConnection = $config['default_connection']; | ||
|
||
$container->setAlias('database_connection', sprintf('doctrine.dbal.%s_connection', $this->defaultConnection)); | ||
|
@@ -92,9 +119,11 @@ protected function dbalLoad(array $config, ContainerBuilder $container) | |
$container->setParameter('doctrine.dbal.connection_factory.types', $config['types']); | ||
|
||
$connections = array(); | ||
|
||
foreach (array_keys($config['connections']) as $name) { | ||
$connections[$name] = sprintf('doctrine.dbal.%s_connection', $name); | ||
} | ||
|
||
$container->setParameter('doctrine.connections', $connections); | ||
$container->setParameter('doctrine.default_connection', $this->defaultConnection); | ||
|
||
|
@@ -506,7 +535,7 @@ protected function loadOrmEntityManagerMappingInformation(array $entityManager, | |
|
||
/** | ||
* Loads an ORM second level cache bundle mapping information. | ||
* | ||
* | ||
* @example | ||
* entity_managers: | ||
* default: | ||
|
@@ -652,6 +681,20 @@ protected function getMappingResourceExtension() | |
return 'orm'; | ||
} | ||
|
||
protected function loadCacheDriver($driverName, $entityManager, $driverMap, $container) | ||
{ | ||
if (!empty($driverMap['cache_provider'])) { | ||
$aliasId = $this->getObjectManagerElementName($driverName); | ||
$serviceId = printf('doctrine_cache.providers.%s', $driverMap['cache_provider']); | ||
|
||
$container->setAlias($aliasId, new Alias($serviceId, false)); | ||
|
||
return; | ||
} | ||
|
||
return $this->adapter->loadCacheDriver($driverName, $entityManager, $driverMap, $container); | ||
} | ||
|
||
/** | ||
* Loads a configured entity managers cache drivers. | ||
* | ||
|
@@ -660,9 +703,19 @@ protected function getMappingResourceExtension() | |
*/ | ||
protected function loadOrmCacheDrivers(array $entityManager, ContainerBuilder $container) | ||
{ | ||
$this->loadObjectManagerCacheDriver($entityManager, $container, 'metadata_cache'); | ||
$this->loadObjectManagerCacheDriver($entityManager, $container, 'result_cache'); | ||
$this->loadObjectManagerCacheDriver($entityManager, $container, 'query_cache'); | ||
$this->loadCacheDriver('metadata_cache', $entityManager['name'], $entityManager['metadata_cache_driver'], $container); | ||
$this->loadCacheDriver('result_cache', $entityManager['name'], $entityManager['result_cache_driver'], $container); | ||
$this->loadCacheDriver('query_cache', $entityManager['name'], $entityManager['query_cache_driver'], $container); | ||
} | ||
|
||
/** | ||
* @param array $objectManager | ||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container | ||
* @param string $cacheName | ||
*/ | ||
public function loadObjectManagerCacheDriver(array $objectManager, ContainerBuilder $container, $cacheName) | ||
{ | ||
$this->loadCacheDriver($cacheName, $objectManager['name'], $objectManager[$cacheName.'_driver'], $container); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters