Skip to content

Commit

Permalink
Implement changes in PR doctrine#13
Browse files Browse the repository at this point in the history
The PR just needed a rebase
  • Loading branch information
silverbackdan committed Feb 9, 2018
1 parent 1a06c65 commit c56ac25
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 61 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.phar
composer.lock
vendor
.idea
3 changes: 2 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ 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('id')->end()
->scalarNode('host')->end()
->scalarNode('port')->end()
->scalarNode('instance_class')->end()
Expand Down
60 changes: 1 addition & 59 deletions DependencyInjection/DoctrineCouchDBExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ protected function loadOdmDocumentManagerMappingInformation(array $documentManag
}
}


$odmConfig->addMethodCall('setDocumentNamespaces', array($this->aliasMap));
}

Expand Down Expand Up @@ -239,64 +238,7 @@ protected function loadOdmDocumentManagerDesignDocuments(array $documentManager,
*/
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)->setPublic(true);
}

/**
* 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)->setPublic(true);
$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)
Expand Down
1 change: 1 addition & 0 deletions Tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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
)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,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
)));
}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"symfony/framework-bundle": "~2.3|~3.0|~4.0"
},
"require-dev": {
"phpunit/phpunit": "^6.5"
"phpunit/phpunit": "^6.5",
"doctrine/couchdb-odm": "*"
},
"suggest": {
},
Expand Down

0 comments on commit c56ac25

Please sign in to comment.