Enabling filter's default parameters in config files #159
Conversation
@@ -60,7 +62,28 @@ private function enableFilters(EntityManager $entityManager) | |||
|
|||
$filterCollection = $entityManager->getFilters(); | |||
foreach ($this->enabledFilters as $filter) { | |||
$filterCollection->enable($filter); | |||
$oFilter = $filterCollection->enable($filter); |
stof
Feb 25, 2013
Member
Why oFilter ?
Why oFilter ?
JJK801
Feb 25, 2013
Author
$filter is the filter name and $oFilter the filter object, is it a problem?
$filter is the filter name and $oFilter the filter object, is it a problem?
stof
Feb 25, 2013
Member
we are not using the o*
, s*
convention to name variable starting with their type. So it is weird to have it used in a single place.
we are not using the o*
, s*
convention to name variable starting with their type. So it is weird to have it used in a single place.
JJK801
Feb 25, 2013
Author
ok, $filterObject sounds better?
ok, $filterObject sounds better?
<xsd:element name="parameters" type="parameters" minOccurs="0" maxOccurs="1" /> | ||
</xsd:choice> | ||
<xsd:attribute name="name" type="xsd:string" use="required" /> | ||
<xsd:attribute name="class" type="xsd:string" /> |
stof
Feb 25, 2013
Member
This is a BC break for XML users
This is a BC break for XML users
JJK801
Feb 25, 2013
Author
I've run some tests and seems good with class as node value as the current config
I've run some tests and seems good with class as node value as the current config
stof
Feb 25, 2013
Member
yeah, I missed mixed="true"
yeah, I missed mixed="true"
<filter name="myFilter" enabled="true" class="Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestFilter"> | ||
<parameters> | ||
<parameter name="myParameter">myValue</parameter> | ||
</parameters> |
stof
Feb 25, 2013
Member
It should not look this way in XML but several <parameter>
tags
It should not look this way in XML but several <parameter>
tags
JJK801
Feb 25, 2013
Author
ok
ok
your XML configuration will not work(try to put at lest 2 parameters) as it is not how prototype nodes should be represented. |
/** | ||
* Enable filters for an given entity manager | ||
* | ||
* @param EntityManager $entityManager |
stof
Feb 25, 2013
Member
This is wrong
This is wrong
JJK801
Feb 25, 2013
Author
oh yes, i missed that...
oh yes, i missed that...
This will fix previouly said bad things |
@@ -60,7 +62,28 @@ private function enableFilters(EntityManager $entityManager) | |||
|
|||
$filterCollection = $entityManager->getFilters(); | |||
foreach ($this->enabledFilters as $filter) { | |||
$filterCollection->enable($filter); | |||
$filterObject = $filterCollection->enable($filter); | |||
if( null !== $filterObject ) { |
stof
Feb 25, 2013
Member
spaces should be around the braces, not inside them
spaces should be around the braces, not inside them
JJK801
Feb 25, 2013
Author
ok, i will fix it
ok, i will fix it
* Set defaults parameters for a given filter | ||
* | ||
* @param string $name Filter name | ||
* @param object $filter Filter object |
stof
Feb 25, 2013
Member
instead of object
, it would be better to use SQLFilter
as it is the actual requirement (I would even typehint it)
instead of object
, it would be better to use SQLFilter
as it is the actual requirement (I would even typehint it)
JJK801
Feb 25, 2013
Author
I was not sure SQLFilter is a requirement, so i'm going to implement it
I was not sure SQLFilter is a requirement, so i'm going to implement it
foreach ($calls as $call) { | ||
if ($call[0] == $methodName) { | ||
if ($called > $nbCalls) { break; } | ||
else { |
stof
Feb 25, 2013
Member
Please follow the Symfony2 CS
Please follow the Symfony2 CS
JJK801
Feb 25, 2013
Author
Ok sorry, my CS may be a little bit outdated :/
Ok sorry, my CS may be a little bit outdated :/
} else { | ||
$this->fail("Method '".$methodName."' is expected to be called ". $nbCalls ." time, definition contain ". $called ." calls."); | ||
} | ||
} |
stof
Feb 25, 2013
Member
I would replace all this with
$this->assertEquals($nbCalls, $call, sprintf('The method "%s" should be called %d times', $methodName, $nbCalls));
I would replace all this with
$this->assertEquals($nbCalls, $call, sprintf('The method "%s" should be called %d times', $methodName, $nbCalls));
JJK801
Feb 25, 2013
Author
my first choice was similar but i changed it to get the same model as assertDICDefinitionMethodCallOnce, but you're right, this solution is much better
my first choice was similar but i changed it to get the same model as assertDICDefinitionMethodCallOnce, but you're right, this solution is much better
if ($call[0] == $methodName) { | ||
if ($called > $nbCalls) { break; } | ||
else { | ||
if ($params[$called] !== null) { |
stof
Feb 25, 2013
Member
what if it is not set ?
what if it is not set ?
JJK801
Feb 25, 2013
Author
:/ lets fix it ;)
:/ lets fix it ;)
@@ -15,6 +15,7 @@ | |||
namespace Doctrine\Bundle\DoctrineBundle; | |||
|
|||
use Doctrine\ORM\EntityManager; | |||
use Doctrine\ORM\Query\Filter\SQLFilter; |
stof
Feb 26, 2013
Member
there is an extra space here
there is an extra space here
*/ | ||
private function setFilterParameters($name, SQLFilter $filter) | ||
{ | ||
if( !empty($this->filtersParameters[$name]) ) { |
stof
Feb 26, 2013
Member
space spacing issue several times in this method
space spacing issue several times in this method
if ($call[0] == $methodName) { | ||
if ($called > $nbCalls) { | ||
break; | ||
} else { |
stof
Feb 26, 2013
Member
no need to use else
as you are breaking the loop in the if
no need to use else
as you are breaking the loop in the if
+1 -- I need this functionality as well (ability to set parameters for filters within config). |
|
Enabling filter's default parameters in config files
Is there a way to use the service container to inject a value? Eg, I have a Site Context and I want to use the SiteId from that Entity. May relate to #134 |
Hi stof,
This update is comming from troubles we had to set a filter parameter at the application start, it enable default values in the config files without breaking older configs.
Jérémy