From 05830ec195bb8df423f2c5f0479b4c332c890a32 Mon Sep 17 00:00:00 2001 From: Bilal Amarni Date: Thu, 10 May 2012 19:22:04 +0200 Subject: [PATCH 1/3] using doctrine abstract extension to load cache driver --- .../DoctrineCouchDBExtension.php | 60 +------------------ Tests/ContainerTest.php | 1 + .../AbstractDoctrineExtensionTest.php | 1 + composer.json | 3 + 4 files changed, 6 insertions(+), 59 deletions(-) diff --git a/DependencyInjection/DoctrineCouchDBExtension.php b/DependencyInjection/DoctrineCouchDBExtension.php index 8d88da4..6dd1337 100644 --- a/DependencyInjection/DoctrineCouchDBExtension.php +++ b/DependencyInjection/DoctrineCouchDBExtension.php @@ -211,7 +211,6 @@ protected function loadOdmDocumentManagerMappingInformation(array $documentManag } } - $odmConfig->addMethodCall('setDocumentNamespaces', array($this->aliasMap)); } @@ -223,64 +222,7 @@ protected function loadOdmDocumentManagerMappingInformation(array $documentManag */ protected function loadOdmCacheDrivers(array $documentManager, ContainerBuilder $container) { - $this->loadOdmDocumentManagerCacheDriver($documentManager, $container, 'metadata_cache'); - } - - /** - * Loads a configured document managers metadata, query or result cache driver. - * - * @param array $documentManager A configured ORM document manager. - * @param ContainerBuilder $container A ContainerBuilder instance - * @param string $cacheName - */ - protected function loadOdmDocumentManagerCacheDriver(array $documentManager, ContainerBuilder $container, $cacheName) - { - $cacheDriverService = sprintf('doctrine_couchdb.odm.%s_%s', $documentManager['name'], $cacheName); - - $driver = $cacheName."_driver"; - $cacheDef = $this->getDocumentManagerCacheDefinition($documentManager, $documentManager[$driver], $container); - $container->setDefinition($cacheDriverService, $cacheDef); - } - - /** - * Gets an document manager cache driver definition for caches. - * - * @param array $documentManager The array configuring an document manager. - * @param array $cacheDriver The cache driver configuration. - * @param ContainerBuilder $container - * @return Definition $cacheDef - */ - protected function getDocumentManagerCacheDefinition(array $documentManager, $cacheDriver, ContainerBuilder $container) - { - switch ($cacheDriver['type']) { - case 'memcache': - $memcacheClass = !empty($cacheDriver['class']) ? $cacheDriver['class'] : '%doctrine_couchdb.odm.cache.memcache.class%'; - $memcacheInstanceClass = !empty($cacheDriver['instance_class']) ? $cacheDriver['instance_class'] : '%doctrine_couchdb.odm.cache.memcache_instance.class%'; - $memcacheHost = !empty($cacheDriver['host']) ? $cacheDriver['host'] : '%doctrine_couchdb.odm.cache.memcache_host%'; - $memcachePort = !empty($cacheDriver['port']) ? $cacheDriver['port'] : '%doctrine_couchdb.odm.cache.memcache_port%'; - $cacheDef = new Definition($memcacheClass); - $memcacheInstance = new Definition($memcacheInstanceClass); - $memcacheInstance->addMethodCall('connect', array( - $memcacheHost, $memcachePort - )); - $container->setDefinition(sprintf('doctrine_couchdb.odm.%s_memcache_instance', $documentManager['name']), $memcacheInstance); - $cacheDef->addMethodCall('setMemcache', array(new Reference(sprintf('doctrine_couchdb.odm.%s_memcache_instance', $documentManager['name'])))); - break; - case 'apc': - case 'array': - case 'xcache': - $cacheDef = new Definition('%'.sprintf('doctrine_couchdb.odm.cache.%s.class', $cacheDriver['type']).'%'); - break; - default: - throw new \InvalidArgumentException(sprintf('"%s" is an unrecognized Doctrine cache driver.', $cacheDriver['type'])); - } - - $cacheDef->setPublic(false); - // generate a unique namespace for the given application - $namespace = 'sf2couchdb_'.$documentManager['name'].'_'.md5($container->getParameter('kernel.root_dir')); - $cacheDef->addMethodCall('setNamespace', array($namespace)); - - return $cacheDef; + $this->loadObjectManagerCacheDriver($documentManager, $container, 'metadata_cache'); } protected function getObjectManagerElementName($name) diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php index b1f33d3..3db18f2 100644 --- a/Tests/ContainerTest.php +++ b/Tests/ContainerTest.php @@ -47,6 +47,7 @@ public function createYamlBundleTestContainer() 'kernel.debug' => false, 'kernel.bundles' => array('YamlBundle' => 'Fixtures\Bundles\YamlBundle\YamlBundle'), 'kernel.cache_dir' => sys_get_temp_dir(), + 'kernel.environment' => 'test', 'kernel.root_dir' => __DIR__ . "/../../../../" // src dir ))); diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index 883a037..3edadcb 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -126,6 +126,7 @@ protected function getContainer($bundles = 'YamlBundle', $vendor = null) 'kernel.debug' => false, 'kernel.bundles' => $map, 'kernel.cache_dir' => sys_get_temp_dir(), + 'kernel.environment' => 'test', 'kernel.root_dir' => __DIR__ . "/../../../../../" // src dir ))); } diff --git a/composer.json b/composer.json index 99e70ea..8f3b39e 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,9 @@ "doctrine/couchdb": "*", "symfony/symfony": "2.1.*" }, + "require-dev": { + "doctrine/couchdb-odm": "*" + }, "suggest": { "doctrine/couchdb-odm": "*" }, From 23c54acc20b9070958fc1316db2e119e19abafc2 Mon Sep 17 00:00:00 2001 From: Bilal Amarni Date: Thu, 10 May 2012 22:08:42 +0200 Subject: [PATCH 2/3] small fixes --- .gitignore | 1 + DependencyInjection/Configuration.php | 2 +- Tests/bootstrap.php | 11 ----------- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 987e2a2..7a8a0ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +composer.phar composer.lock vendor diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 5416c1a..03cd680 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -234,7 +234,7 @@ private function getOdmCacheDriverNode($name) ->then(function($v) { return array('type' => $v); }) ->end() ->children() - ->scalarNode('type')->defaultValue('array')->isRequired()->end() + ->scalarNode('type')->defaultValue('array')->end() ->scalarNode('host')->end() ->scalarNode('port')->end() ->scalarNode('instance_class')->end() diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 8cbe855..0143f9e 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -6,14 +6,3 @@ php composer.phar install "); } - -spl_autoload_register(function($class) { - if (0 === strpos($class, 'Doctrine\\Bundle\\CouchDBBundle')) { - $path = __DIR__.'/../'.implode('/', array_slice(explode('\\', $class), 3)).'.php'; - if (!stream_resolve_include_path($path)) { - return false; - } - require_once $path; - return true; - } -}); \ No newline at end of file From cd3819b1a182f70fa315d65768e36c3c80fe8a79 Mon Sep 17 00:00:00 2001 From: Bilal Amarni Date: Fri, 18 May 2012 22:44:11 +0200 Subject: [PATCH 3/3] added service id --- DependencyInjection/Configuration.php | 1 + 1 file changed, 1 insertion(+) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 03cd680..46f2edf 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -235,6 +235,7 @@ private function getOdmCacheDriverNode($name) ->end() ->children() ->scalarNode('type')->defaultValue('array')->end() + ->scalarNode('id')->end() ->scalarNode('host')->end() ->scalarNode('port')->end() ->scalarNode('instance_class')->end()