Skip to content

Commit

Permalink
add attribute driver support
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan committed Aug 11, 2021
1 parent cfa2ec4 commit 9e56b2d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler;

use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver;
use Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver;
use Doctrine\Persistence\Mapping\Driver\PHPDriver;
use Doctrine\Persistence\Mapping\Driver\StaticPHPDriver;
Expand Down Expand Up @@ -112,6 +113,27 @@ public static function createAnnotationMappingDriver(array $namespaces, array $d
return new DoctrineMongoDBMappingsPass($driver, $namespaces, $managerParameters, $enabledParameter, $aliasMap);
}

/**
* @param array $namespaces List of namespaces that are handled with attribute mapping
* @param array $directories List of directories to look for attribute mapping files
* @param string[] $managerParameters List of parameters that could which object manager name
* your bundle uses. This compiler pass will automatically
* append the parameter name for the default entity manager
* to this list.
* @param string|false $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.
*
* @return DoctrineMongoDBMappingsPass
*/
public static function createAttributeMappingDriver(array $namespaces, array $directories, array $managerParameters, $enabledParameter = false, array $aliasMap = [])
{
$driver = new Definition(AttributeDriver::class, [$directories, new Reference('doctrine_mongodb.odm.metadata.attribute_reader')]);

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

/**
* @param array $namespaces List of namespaces that are handled with static php mapping
* @param array $directories List of directories to look for static php mapping files
Expand Down
7 changes: 7 additions & 0 deletions Resources/config/mongodb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<!-- metadata -->
<parameter key="doctrine_mongodb.odm.metadata.driver_chain.class">Doctrine\Persistence\Mapping\Driver\MappingDriverChain</parameter>
<parameter key="doctrine_mongodb.odm.metadata.annotation.class">Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver</parameter>
<parameter key="doctrine_mongodb.odm.metadata.attribute.class">Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver</parameter>
<parameter key="doctrine_mongodb.odm.metadata.attribute_reader.class">Doctrine\ODM\MongoDB\Mapping\Driver\AttributeReader</parameter>
<parameter key="doctrine_mongodb.odm.metadata.xml.class">Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver</parameter>

<!-- directories -->
Expand Down Expand Up @@ -115,6 +117,11 @@
<argument>%doctrine_mongodb.odm.document_dirs%</argument>
</service>
<service id="doctrine_mongodb.odm.metadata.annotation_reader" alias="annotation_reader" />
<service id="doctrine_mongodb.odm.metadata.attribute" class="%doctrine_mongodb.odm.metadata.attribute.class%">
<argument>%doctrine_mongodb.odm.document_dirs%</argument>
<argument type="service" id="doctrine_mongodb.odm.metadata.attribute_reader" />
</service>
<service id="doctrine_mongodb.odm.metadata.attribute_reader" class="%doctrine_mongodb.odm.metadata.attribute_reader.class%" />
<service id="doctrine_mongodb.odm.metadata.xml" class="%doctrine_mongodb.odm.metadata.xml.class%">
<argument>%doctrine_mongodb.odm.xml_mapping_dirs%</argument>
</service>
Expand Down

0 comments on commit 9e56b2d

Please sign in to comment.