Permalink
Browse files

Added default parameters for query filters

  • Loading branch information...
1 parent 6c6e2cf commit 8610564a37908138287ff8d0acc8b9b931b580e2 @JJK801 JJK801 committed Feb 22, 2013
@@ -378,6 +378,9 @@ private function getOrmEntityManagersNode()
->children()
->scalarNode('class')->isRequired()->end()
->booleanNode('enabled')->defaultFalse()->end()
+ ->arrayNode('parameters')
+ ->prototype('variable')->end()
+ ->end()
->end()
->end()
->end()
@@ -321,17 +321,22 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
}
$enabledFilters = array();
+ $filtersParameters = array();
foreach ($entityManager['filters'] as $name => $filter) {
$ormConfigDef->addMethodCall('addFilter', array($name, $filter['class']));
if ($filter['enabled']) {
$enabledFilters[] = $name;
}
+ if ($filter['parameters']) {
+ $filtersParameters[$name] = $filter['parameters'];
+ }
}
$managerConfiguratorName = sprintf('doctrine.orm.%s_manager_configurator', $entityManager['name']);
$managerConfiguratorDef = $container
->setDefinition($managerConfiguratorName, new DefinitionDecorator('doctrine.orm.manager_configurator.abstract'))
->replaceArgument(0, $enabledFilters)
+ ->replaceArgument(1, $filtersParameters)
;
if (!isset($entityManager['connection'])) {
View
@@ -24,15 +24,17 @@
class ManagerConfigurator
{
private $enabledFilters = array();
+ private $filtersParameters = array();
/**
* Construct.
*
* @param array $enabledFilters
*/
- public function __construct(array $enabledFilters)
+ public function __construct(array $enabledFilters, array $filtersParameters)
{
$this->enabledFilters = $enabledFilters;
+ $this->filtersParameters = $filtersParameters;
}
/**
@@ -60,7 +62,28 @@ private function enableFilters(EntityManager $entityManager)
$filterCollection = $entityManager->getFilters();
foreach ($this->enabledFilters as $filter) {
- $filterCollection->enable($filter);
+ $oFilter = $filterCollection->enable($filter);
+ if( null !== $oFilter ) {
+ $this->setFilterParameters($filter, $oFilter);
+ }
}
}
+
+ /**
+ * Enable filters for an given entity manager
+ *
+ * @param EntityManager $entityManager
+ *
+ * @return null
+ */
+ private function setFilterParameters($name, $filter)
+ {
+ if( !empty($this->filtersParameters[$name]) ) {
+ $parameters = $this->filtersParameters[$name];
+ foreach( $parameters as $paramName => $paramValue ) {
+ $filter->setParameter($paramName, $paramValue);
+ }
+ }
+ return $this;
+ }
}
View
@@ -83,6 +83,7 @@
<!-- The configurator cannot be a private service -->
<service id="doctrine.orm.manager_configurator.abstract" class="%doctrine.orm.manager_configurator.class%" abstract="true">
<argument type="collection" />
+ <argument type="collection" />
</service>
<!-- validator -->
@@ -765,7 +765,7 @@ public function testAddFilter()
$this->assertDICDefinitionMethodCallOnce($definition, 'addFilter', array('soft_delete', 'Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestFilter'));
$definition = $container->getDefinition('doctrine.orm.default_manager_configurator');
- $this->assertDICConstructorArguments($definition, array(array('soft_delete')));
+ $this->assertDICConstructorArguments($definition, array(array('soft_delete'), array()));
// Let's create the instance to check the configurator work.
/** @var $entityManager \Doctrine\ORM\EntityManager */

0 comments on commit 8610564

Please sign in to comment.