-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add compiler pass for bundles to register mappings #185
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7dcac3d
add compiler pass for bundles to register mappings
dbu 0c962f0
adjusting to https://github.com/symfony/symfony/pull/7755
dbu c2ea86b
add php and staticphp driver support to compiler pass
dbu 211233a
this is part of MongoDBBundle, remove unnecessary class alias
dbu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Doctrine Bundle | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterMappingsPass as BaseMappingPass; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Class for Symfony bundles to configure mappings for model classes not in the | ||
* automapped folder. | ||
* | ||
* @author David Buchmann <david@liip.ch> | ||
*/ | ||
class DoctrineMongoDBMappingsPass extends BaseMappingPass | ||
{ | ||
/** | ||
* You should not directly instantiate this class but use one of the | ||
* factory methods. | ||
* | ||
* @param Definition|Reference $driver the driver to use | ||
* @param array $namespaces list of namespaces this driver should handle | ||
* @param bool $enabledParameter if specified, the compiler pass only | ||
* executes if this parameter exists in the service container. | ||
*/ | ||
public function __construct($driver, $namespaces, $enabledParameter = false) | ||
{ | ||
parent::__construct( | ||
$driver, | ||
$namespaces, | ||
'doctrine_mongodb.odm.document_managers', | ||
'doctrine_mongodb.odm.%s_metadata_driver', | ||
$enabledParameter | ||
); | ||
|
||
} | ||
|
||
/** | ||
* @param array $mappings Hashmap of directory path to namespace | ||
* @param string $enabledParameter Service container parameter that must be | ||
* present to enable the mapping. Set to false to not do any check, optional. | ||
*/ | ||
public static function createXmlMappingDriver(array $mappings, $enabledParameter = false) | ||
{ | ||
$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, $enabledParameter); | ||
} | ||
|
||
/** | ||
* @param array $mappings Hashmap of directory path to namespace | ||
* @param string $enabledParameter Service container parameter that must be | ||
* present to enable the mapping. Set to false to not do any check, optional. | ||
*/ | ||
public static function createYamlMappingDriver(array $mappings, $enabledParameter = false) | ||
{ | ||
$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, $enabledParameter); | ||
} | ||
|
||
/** | ||
* @param array $namespaces List of namespaces that are handled with annotation mapping | ||
* @param array $directories List of directories to look for annotation mapping files | ||
* @param string $enabledParameter Service container parameter that must be | ||
* present to enable the mapping. Set to false to not do any check, optional. | ||
*/ | ||
public static function createAnnotationMappingDriver(array $namespaces, array $directories, $enabledParameter = false) | ||
{ | ||
$arguments = array(new Reference('doctrine_mongodb.odm.metadata.annotation_reader'), $directories); | ||
$locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator', $arguments); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong (same than in the doctrineBundle) |
||
$driver = new Definition('Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver', array($locator)); | ||
|
||
return new DoctrineMongoDBMappingsPass($driver, $namespaces, $enabledParameter); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong