Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Automatically register a FolderDesignDocument for CouchDB ODM at exis…

…ting Resources/couchdb/<connname> directory
  • Loading branch information...
commit 4aed418c19175ff52597521aef20f0be5a6e1713 1 parent c9e02a1
@beberlei beberlei authored
View
3  DependencyInjection/Configuration.php
@@ -128,7 +128,7 @@ private function addOdmSection(ArrayNodeDefinition $node)
'metadata_cache_driver', 'metadata-cache-driver',
'auto_mapping', 'auto-mapping',
'mappings', 'mapping',
- 'connection'
+ 'connection',
) as $key) {
if (array_key_exists($key, $v)) {
$documentManagers[$key] = $v[$key];
@@ -204,6 +204,7 @@ private function getOdmDocumentManagersNode()
->end()
->scalarNode('lucene_handler_name')->defaultFalse()->end()
->scalarNode('uuid_buffer_size')->defaultValue(20)->end()
+ ->scalarNode('view_name')->defaultValue('symfony')->end()
->booleanNode('all_or_nothing_flush')->defaultTrue()->end()
->end()
->end()
View
23 DependencyInjection/DoctrineCouchDBExtension.php
@@ -29,6 +29,8 @@
class DoctrineCouchDBExtension extends AbstractDoctrineExtension
{
private $documentManagers;
+
+ private $bundleDirs = array();
public function load(array $configs, ContainerBuilder $container)
{
@@ -146,7 +148,7 @@ private function loadOdmDocumentManager($documentManager, ContainerBuilder $cont
foreach ($methods as $method => $arg) {
$odmConfigDef->addMethodCall($method, array($arg));
}
-
+
if (!isset($documentManager['connection'])) {
$documentManager['connection'] = $this->defaultConnection;
}
@@ -162,15 +164,34 @@ private function loadOdmDocumentManager($documentManager, ContainerBuilder $cont
))
;
}
+
+ protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \ReflectionClass $bundle, ContainerBuilder $container)
+ {
+ $this->bundleDirs[] = dirname($bundle->getFileName());
+
+ return parent::getMappingDriverBundleConfigDefaults($bundleConfig, $bundle, $container);
+ }
+
protected function loadOdmDocumentManagerMappingInformation(array $documentManager, Definition $odmConfig, ContainerBuilder $container)
{
// reset state of drivers and alias map. They are only used by this methods and children.
$this->drivers = array();
$this->aliasMap = array();
+ $this->bundleDirs = array();
$this->loadMappingInformation($documentManager, $container);
$this->registerMappingDrivers($documentManager, $container);
+
+ foreach ($this->bundleDirs AS $bundleDir) {
+ if (is_dir($bundleDir."/Resources/couchdb/" . $documentManager['name'])) {
+ $odmConfig->addMethodCall('addDesignDocument', array(
+ $documentManager['view_name'],
+ 'Doctrine\CouchDB\View\FolderDesignDocument',
+ array($bundleDir."/Resources/couchdb/" . $documentManager['name'])
+ ));
+ }
+ }
$odmConfig->addMethodCall('setDocumentNamespaces', array($this->aliasMap));
}
View
3  Tests/DependencyInjection/ConfigurationTest.php
@@ -115,6 +115,7 @@ public function testSingleTopLevelDocumentManager()
'design_documents' => array(),
'lucene_handler_name' => false,
'uuid_buffer_size' => 20,
+ 'view_name' => 'symfony',
'all_or_nothing_flush' => true,
),
),
@@ -152,6 +153,7 @@ public function testMultipleDocumentManager()
'design_documents' => array(),
'lucene_handler_name' => false,
'uuid_buffer_size' => 20,
+ 'view_name' => 'symfony',
'all_or_nothing_flush' => true,
),
'test2' => array(
@@ -161,6 +163,7 @@ public function testMultipleDocumentManager()
'design_documents' => array(),
'lucene_handler_name' => false,
'uuid_buffer_size' => 20,
+ 'view_name' => 'symfony',
'all_or_nothing_flush' => true,
),
),
Please sign in to comment.
Something went wrong with that request. Please try again.