Permalink
Browse files

fixed cache config and using the abstract method

  • Loading branch information...
1 parent 57cc020 commit bb1a415b40b4806cd6cf7be34b46b1c2098238e8 @bamarni bamarni committed May 10, 2012
@@ -82,12 +82,13 @@ private function addDocumentManagersSection(ArrayNodeDefinition $rootNode)
->end()
->scalarNode('auto_mapping')->defaultFalse()->end()
->arrayNode('metadata_cache_driver')
+ ->addDefaultsIfNotSet()
->beforeNormalization()
->ifTrue(function($v) { return !is_array($v); })
->then(function($v) { return array('type' => $v); })
->end()
->children()
- ->scalarNode('type')->end()
+ ->scalarNode('type')->defaultValue('array')->isRequired()->end()
->scalarNode('class')->end()
->scalarNode('host')->end()
->scalarNode('port')->end()
@@ -44,11 +44,6 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
- // can't currently default this correctly in Configuration
- if (!isset($config['metadata_cache_driver'])) {
- $config['metadata_cache_driver'] = array('type' => 'array');
- }
-
if (empty($config['default_connection'])) {
$keys = array_keys($config['connections']);
$config['default_connection'] = reset($keys);
@@ -72,7 +67,6 @@ public function load(array $configs, ContainerBuilder $container)
$config['document_managers'],
$config['default_document_manager'],
$config['default_database'],
- $config['metadata_cache_driver'],
$container
);
}
@@ -112,10 +106,9 @@ protected function overrideParameters($options, ContainerBuilder $container)
* @param array $dmConfigs An array of document manager configs
* @param string $defaultDM The default document manager name
* @param string $defaultDB The default db name
- * @param string $defaultMetadataCache The default metadata cache configuration
* @param ContainerBuilder $container A ContainerBuilder instance
*/
- protected function loadDocumentManagers(array $dmConfigs, $defaultDM, $defaultDB, $defaultMetadataCache, ContainerBuilder $container)
+ protected function loadDocumentManagers(array $dmConfigs, $defaultDM, $defaultDB, ContainerBuilder $container)
{
$dms = array();
foreach ($dmConfigs as $name => $documentManager) {
@@ -124,7 +117,6 @@ protected function loadDocumentManagers(array $dmConfigs, $defaultDM, $defaultDB
$documentManager,
$defaultDM,
$defaultDB,
- $defaultMetadataCache,
$container
);
$dms[$name] = sprintf('doctrine.odm.mongodb.%s_document_manager', $name);
@@ -138,10 +130,9 @@ protected function loadDocumentManagers(array $dmConfigs, $defaultDM, $defaultDB
* @param array $documentManager A document manager configuration array
* @param string $defaultDM The default document manager name
* @param string $defaultDB The default db name
- * @param string $defaultMetadataCache The default metadata cache configuration
* @param ContainerBuilder $container A ContainerBuilder instance
*/
- protected function loadDocumentManager(array $documentManager, $defaultDM, $defaultDB, $defaultMetadataCache, ContainerBuilder $container)
+ protected function loadDocumentManager(array $documentManager, $defaultDM, $defaultDB, ContainerBuilder $container)
{
$configServiceName = sprintf('doctrine.odm.mongodb.%s_configuration', $documentManager['name']);
$connectionName = isset($documentManager['connection']) ? $documentManager['connection'] : $documentManager['name'];
@@ -155,7 +146,7 @@ protected function loadDocumentManager(array $documentManager, $defaultDM, $defa
}
$this->loadDocumentManagerBundlesMappingInformation($documentManager, $odmConfigDef, $container);
- $this->loadDocumentManagerMetadataCacheDriver($documentManager, $container, $defaultMetadataCache);
+ $this->loadObjectManagerCacheDriver($documentManager, $container, 'metadata_cache');
$methods = array(
'setMetadataCacheImpl' => new Reference(sprintf('doctrine.odm.mongodb.%s_metadata_cache', $documentManager['name'])),
@@ -227,44 +218,6 @@ protected function loadDocumentManager(array $documentManager, $defaultDM, $defa
}
/**
- * Loads the configured document manager metadata cache driver.
- *
- * @param array $config A configured document manager array
- * @param ContainerBuilder $container A ContainerBuilder instance
- * @param array $defaultMetadataCache The default metadata cache configuration array
- */
- protected function loadDocumentManagerMetadataCacheDriver(array $documentManager, ContainerBuilder $container, $defaultMetadataCache)
- {
- $dmMetadataCacheDriver = isset($documentManager['metadata_cache_driver']) ? $documentManager['metadata_cache_driver'] : $defaultMetadataCache;
- $type = $dmMetadataCacheDriver['type'];
- $serviceName = sprintf('doctrine.odm.mongodb.%s_metadata_cache', $documentManager['name']);
-
- if ('service' === $type) {
- $container->setAlias($serviceName, new Alias($dmMetadataCacheDriver['id'], false));
-
- return;
- }
-
- if ('memcache' === $type) {
- $memcacheClass = isset($dmMetadataCacheDriver['class']) ? $dmMetadataCacheDriver['class'] : sprintf('%%doctrine.odm.mongodb.cache.%s.class%%', $type);
- $cacheDef = new Definition($memcacheClass);
- $memcacheHost = isset($dmMetadataCacheDriver['host']) ? $dmMetadataCacheDriver['host'] : '%doctrine.odm.mongodb.cache.memcache_host%';
- $memcachePort = isset($dmMetadataCacheDriver['port']) ? $dmMetadataCacheDriver['port'] : '%doctrine.odm.mongodb.cache.memcache_port%';
- $memcacheInstanceClass = isset($dmMetadataCacheDriver['instance-class']) ? $dmMetadataCacheDriver['instance-class'] : (isset($dmMetadataCacheDriver['instance_class']) ? $dmMetadataCacheDriver['instance_class'] : '%doctrine.odm.mongodb.cache.memcache_instance.class%');
- $memcacheInstance = new Definition($memcacheInstanceClass);
- $memcacheInstance->addMethodCall('connect', array($memcacheHost, $memcachePort));
- $container->setDefinition(sprintf('doctrine.odm.mongodb.%s_memcache_instance', $documentManager['name']), $memcacheInstance);
- $cacheDef->addMethodCall('setMemcache', array(new Reference(sprintf('doctrine.odm.mongodb.%s_memcache_instance', $documentManager['name']))));
- } else {
- $cacheDef = new Definition(sprintf('%%doctrine.odm.mongodb.cache.%s.class%%', $type));
- }
-
- $cacheDef->setPublic(false);
-
- $container->setDefinition($serviceName, $cacheDef);
- }
-
- /**
* Loads the configured connections.
*
* @param array $config An array of connections configurations
View
@@ -29,6 +29,8 @@ protected function setUp()
$this->container = new ContainerBuilder(new ParameterBag(array(
'kernel.bundles' => array(),
'kernel.cache_dir' => sys_get_temp_dir(),
+ 'kernel.root_dir' => sys_get_temp_dir(),
+ 'kernel.environment' => 'test',
'kernel.debug' => true,
)));
@@ -212,7 +212,7 @@ public function optionProvider()
array('document_managers' => array('default' => array('mappings' => array('foomap' => array('type' => 'val1'), 'barmap' => array('dir' => 'val2'))))),
array('document_managers' => array('default' => array('mappings' => array('barmap' => array('prefix' => 'val3'))))),
),
- array('document_managers' => array('default' => array('logging' => '%kernel.debug%', 'profiler' => array('enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'), 'auto_mapping' => false, 'mappings' => array('foomap' => array('type' => 'val1', 'mapping' => true), 'barmap' => array('prefix' => 'val3', 'mapping' => true))))),
+ array('document_managers' => array('default' => array('metadata_cache_driver' => array('type' => 'array'), 'logging' => '%kernel.debug%', 'profiler' => array('enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'), 'auto_mapping' => false, 'mappings' => array('foomap' => array('type' => 'val1', 'mapping' => true), 'barmap' => array('prefix' => 'val3', 'mapping' => true))))),
);
// connections are merged non-recursively.
@@ -234,8 +234,8 @@ public function optionProvider()
array('document_managers' => array('bardm' => array('database' => 'val3'))),
),
array('document_managers' => array(
- 'foodm' => array('database' => 'val1', 'logging' => '%kernel.debug%', 'profiler' => array('enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'), 'auto_mapping' => false, 'mappings' => array()),
- 'bardm' => array('database' => 'val3', 'logging' => '%kernel.debug%', 'profiler' => array('enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'), 'auto_mapping' => false, 'mappings' => array()),
+ 'foodm' => array('database' => 'val1', 'metadata_cache_driver' => array('type' => 'array'), 'logging' => '%kernel.debug%', 'profiler' => array('enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'), 'auto_mapping' => false, 'mappings' => array()),
+ 'bardm' => array('database' => 'val3', 'metadata_cache_driver' => array('type' => 'array'), 'logging' => '%kernel.debug%', 'profiler' => array('enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'), 'auto_mapping' => false, 'mappings' => array()),
)),
);
@@ -250,7 +250,7 @@ public function testNormalizeOptions(array $config, $targetKey, array $normalize
$processor = new Processor();
$configuration = new Configuration(false);
$options = $processor->processConfiguration($configuration, array($config));
- $this->assertSame($normalized, $options[$targetKey]);
+ $this->assertEquals($normalized, $options[$targetKey]);
}
public function getNormalizationTests()
@@ -276,8 +276,8 @@ public function getNormalizationTests()
)),
'document_managers',
array(
- 'foo' => array('connection' => 'conn1', 'logging' => '%kernel.debug%', 'profiler' => array('enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'), 'auto_mapping' => false, 'mappings' => array()),
- 'bar' => array('connection' => 'conn2', 'logging' => '%kernel.debug%', 'profiler' => array('enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'), 'auto_mapping' => false, 'mappings' => array()),
+ 'foo' => array('connection' => 'conn1', 'metadata_cache_driver' => array('type' => 'array'), 'logging' => '%kernel.debug%', 'profiler' => array('enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'), 'auto_mapping' => false, 'mappings' => array()),
+ 'bar' => array('connection' => 'conn2', 'metadata_cache_driver' => array('type' => 'array'), 'logging' => '%kernel.debug%', 'profiler' => array('enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'), 'auto_mapping' => false, 'mappings' => array()),
),
),
// mapping configuration that's beneath a specific document manager
@@ -291,6 +291,7 @@ public function getNormalizationTests()
array(
'foo' => array(
'connection' => 'conn1',
+ 'metadata_cache_driver' => array('type' => 'array'),
'mappings' => array('foo-mapping' => array('type' => 'xml', 'mapping' => true)),
'logging' => '%kernel.debug%',
'profiler' => array('enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'),

0 comments on commit bb1a415

Please sign in to comment.