Skip to content

Commit

Permalink
add support for bundle namespace alias
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Aug 8, 2014
1 parent 59cf093 commit c3d037c
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php
Expand Up @@ -20,6 +20,8 @@
* Class for Symfony bundles to configure mappings for model classes not in the
* automapped folder.
*
* NOTE: alias is only supported by Symfony 2.6+ and will be ignored with older versions.
*
* @author David Buchmann <mail@davidbu.ch>
*/
class DoctrineMongoDBMappingsPass extends RegisterMappingsPass
Expand All @@ -33,16 +35,21 @@ class DoctrineMongoDBMappingsPass extends RegisterMappingsPass
* @param string[] $managerParameters list of parameters that could tell the manager name to use
* @param bool $enabledParameter if specified, the compiler pass only
* executes if this parameter exists in the service container.
* @param string[] $aliasMap Map of alias to namespace.
*/
public function __construct($driver, array $namespaces, array $managerParameters, $enabledParameter = false)
public function __construct($driver, array $namespaces, array $managerParameters, $enabledParameter = false, array $aliasMap = array())
{
$managerParameters[] = 'doctrine_mongodb.odm.default_document_manager';
parent::__construct(
$driver,
$namespaces,
$managerParameters,
'doctrine_mongodb.odm.%s_metadata_driver',
$enabledParameter
$enabledParameter,
'doctrine_mongodb.odm.%s_configuration',
'addDocumentNamespace',
$aliasMap

);

}
Expand All @@ -56,14 +63,15 @@ public function __construct($driver, array $namespaces, array $managerParameters
* @param string $enabledParameter Service container parameter that must be present to
* enable the mapping. Set to false to not do any check,
* optional.
* @param string[] $aliasMap Map of alias to namespace.
*/
public static function createXmlMappingDriver(array $mappings, array $managerParameters, $enabledParameter = false)
public static function createXmlMappingDriver(array $mappings, array $managerParameters, $enabledParameter = false, array $aliasMap = array())
{
$arguments = array($mappings, '.mongodb.xml');
$locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator', $arguments);
$driver = new Definition('Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver', array($locator));

return new DoctrineMongoDBMappingsPass($driver, $mappings, $managerParameters, $enabledParameter);
return new DoctrineMongoDBMappingsPass($driver, $mappings, $managerParameters, $enabledParameter, $aliasMap);
}

/**
Expand All @@ -75,14 +83,15 @@ public static function createXmlMappingDriver(array $mappings, array $managerPar
* @param string $enabledParameter Service container parameter that must be present to
* enable the mapping. Set to false to not do any check,
* optional.
* @param string[] $aliasMap Map of alias to namespace.
*/
public static function createYamlMappingDriver(array $mappings, array $managerParameters, $enabledParameter = false)
public static function createYamlMappingDriver(array $mappings, array $managerParameters, $enabledParameter = false, array $aliasMap = array())
{
$arguments = array($mappings, '.mongodb.yml');
$locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator', $arguments);
$driver = new Definition('Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver', array($locator));

return new DoctrineMongoDBMappingsPass($driver, $mappings, $managerParameters, $enabledParameter);
return new DoctrineMongoDBMappingsPass($driver, $mappings, $managerParameters, $enabledParameter, $aliasMap);
}

/**
Expand All @@ -94,14 +103,15 @@ public static function createYamlMappingDriver(array $mappings, array $managerPa
* @param string $enabledParameter Service container parameter that must be present to
* enable the mapping. Set to false to not do any check,
* optional.
* @param string[] $aliasMap Map of alias to namespace.
*/
public static function createPhpMappingDriver(array $mappings, array $managerParameters = array(), $enabledParameter = false)
public static function createPhpMappingDriver(array $mappings, array $managerParameters = array(), $enabledParameter = false, array $aliasMap = array())
{
$arguments = array($mappings, '.php');
$locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator', $arguments);
$driver = new Definition('Doctrine\Common\Persistence\Mapping\Driver\PHPDriver', array($locator));

return new DoctrineMongoDBMappingsPass($driver, $mappings, $managerParameters, $enabledParameter);
return new DoctrineMongoDBMappingsPass($driver, $mappings, $managerParameters, $enabledParameter, $aliasMap);
}

/**
Expand All @@ -114,14 +124,15 @@ public static function createPhpMappingDriver(array $mappings, array $managerPar
* @param string $enabledParameter Service container parameter that must be present to
* enable the mapping. Set to false to not do any check,
* optional.
* @param string[] $aliasMap Map of alias to namespace.
*/
public static function createAnnotationMappingDriver(array $namespaces, array $directories, array $managerParameters, $enabledParameter = false)
public static function createAnnotationMappingDriver(array $namespaces, array $directories, array $managerParameters, $enabledParameter = false, array $aliasMap = array())
{
$arguments = array(new Reference('doctrine_mongodb.odm.metadata.annotation_reader'), $directories);
$locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator', $arguments);
$driver = new Definition('Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver', array($locator));

return new DoctrineMongoDBMappingsPass($driver, $namespaces, $managerParameters, $enabledParameter);
return new DoctrineMongoDBMappingsPass($driver, $namespaces, $managerParameters, $enabledParameter, $aliasMap);
}

/**
Expand All @@ -134,11 +145,12 @@ public static function createAnnotationMappingDriver(array $namespaces, array $d
* @param string $enabledParameter Service container parameter that must be present to
* enable the mapping. Set to false to not do any check,
* optional.
* @param string[] $aliasMap Map of alias to namespace.
*/
public static function createStaticPhpMappingDriver(array $namespaces, array $directories, array $managerParameters = array(), $enabledParameter = false)
public static function createStaticPhpMappingDriver(array $namespaces, array $directories, array $managerParameters = array(), $enabledParameter = false, array $aliasMap = array())
{
$driver = new Definition('Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver', array($directories));

return new DoctrineMongoDBMappingsPass($driver, $namespaces, $managerParameters, $enabledParameter);
return new DoctrineMongoDBMappingsPass($driver, $namespaces, $managerParameters, $enabledParameter, $aliasMap);
}
}

0 comments on commit c3d037c

Please sign in to comment.