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

Enabling filter's default parameters in config files #159

Merged
merged 7 commits into from Mar 5, 2013

Conversation

Projects
None yet
5 participants
@JJK801
Contributor

JJK801 commented Feb 25, 2013

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

@stof

View changes

ManagerConfigurator.php Outdated
@@ -60,7 +62,28 @@ private function enableFilters(EntityManager $entityManager)
$filterCollection = $entityManager->getFilters();
foreach ($this->enabledFilters as $filter) {
$filterCollection->enable($filter);
$oFilter = $filterCollection->enable($filter);

This comment has been minimized.

@stof

stof Feb 25, 2013

Member

Why oFilter ?

This comment has been minimized.

@JJK801

JJK801 Feb 25, 2013

Contributor

$filter is the filter name and $oFilter the filter object, is it a problem?

This comment has been minimized.

@stof

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.

This comment has been minimized.

@JJK801

JJK801 Feb 25, 2013

Contributor

ok, $filterObject sounds better?

@stof

View changes

Resources/config/schema/doctrine-1.0.xsd Outdated
<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" />

This comment has been minimized.

@stof

stof Feb 25, 2013

Member

This is a BC break for XML users

This comment has been minimized.

@JJK801

JJK801 Feb 25, 2013

Contributor

I've run some tests and seems good with class as node value as the current config

This comment has been minimized.

@stof

stof Feb 25, 2013

Member

yeah, I missed mixed="true"

@stof

View changes

Tests/DependencyInjection/Fixtures/config/xml/orm_filters.xml Outdated
<filter name="myFilter" enabled="true" class="Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestFilter">
<parameters>
<parameter name="myParameter">myValue</parameter>
</parameters>

This comment has been minimized.

@stof

stof Feb 25, 2013

Member

It should not look this way in XML but several <parameter> tags

This comment has been minimized.

@JJK801

JJK801 Feb 25, 2013

Contributor

ok

@stof

This comment has been minimized.

Member

stof commented Feb 25, 2013

your XML configuration will not work(try to put at lest 2 parameters) as it is not how prototype nodes should be represented.

@stof

View changes

ManagerConfigurator.php Outdated
/**
* Enable filters for an given entity manager
*
* @param EntityManager $entityManager

This comment has been minimized.

@stof

stof Feb 25, 2013

Member

This is wrong

This comment has been minimized.

@JJK801

JJK801 Feb 25, 2013

Contributor

oh yes, i missed that...

@JJK801

This comment has been minimized.

Contributor

JJK801 commented Feb 25, 2013

This will fix previouly said bad things

@stof

View changes

ManagerConfigurator.php Outdated
@@ -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 ) {

This comment has been minimized.

@stof

stof Feb 25, 2013

Member

spaces should be around the braces, not inside them

This comment has been minimized.

@JJK801

JJK801 Feb 25, 2013

Contributor

ok, i will fix it

@stof

View changes

ManagerConfigurator.php Outdated
* Set defaults parameters for a given filter
*
* @param string $name Filter name
* @param object $filter Filter object

This comment has been minimized.

@stof

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)

This comment has been minimized.

@JJK801

JJK801 Feb 25, 2013

Contributor

I was not sure SQLFilter is a requirement, so i'm going to implement it

@stof

View changes

Tests/DependencyInjection/AbstractDoctrineExtensionTest.php Outdated
foreach ($calls as $call) {
if ($call[0] == $methodName) {
if ($called > $nbCalls) { break; }
else {

This comment has been minimized.

@stof

stof Feb 25, 2013

Member

Please follow the Symfony2 CS

This comment has been minimized.

@JJK801

JJK801 Feb 25, 2013

Contributor

Ok sorry, my CS may be a little bit outdated :/

@stof

View changes

Tests/DependencyInjection/AbstractDoctrineExtensionTest.php Outdated
} else {
$this->fail("Method '".$methodName."' is expected to be called ". $nbCalls ." time, definition contain ". $called ." calls.");
}
}

This comment has been minimized.

@stof

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));

This comment has been minimized.

@JJK801

JJK801 Feb 25, 2013

Contributor

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

@stof

View changes

Tests/DependencyInjection/AbstractDoctrineExtensionTest.php Outdated
if ($call[0] == $methodName) {
if ($called > $nbCalls) { break; }
else {
if ($params[$called] !== null) {

This comment has been minimized.

@stof

stof Feb 25, 2013

Member

what if it is not set ?

This comment has been minimized.

@JJK801

JJK801 Feb 25, 2013

Contributor

:/ lets fix it ;)

@stof

View changes

ManagerConfigurator.php Outdated
@@ -15,6 +15,7 @@
namespace Doctrine\Bundle\DoctrineBundle;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query\Filter\SQLFilter;

This comment has been minimized.

@stof

stof Feb 26, 2013

Member

there is an extra space here

@stof

View changes

ManagerConfigurator.php Outdated
*/
private function setFilterParameters($name, SQLFilter $filter)
{
if( !empty($this->filtersParameters[$name]) ) {

This comment has been minimized.

@stof

stof Feb 26, 2013

Member

space spacing issue several times in this method

@stof

View changes

Tests/DependencyInjection/AbstractDoctrineExtensionTest.php Outdated
if ($call[0] == $methodName) {
if ($called > $nbCalls) {
break;
} else {

This comment has been minimized.

@stof

stof Feb 26, 2013

Member

no need to use else as you are breaking the loop in the if

@intel352

This comment has been minimized.

intel352 commented Mar 3, 2013

+1 -- I need this functionality as well (ability to set parameters for filters within config).

@omansour

This comment has been minimized.

omansour commented Mar 4, 2013

👍 we need this PR at work

stof added a commit that referenced this pull request Mar 5, 2013

Merge pull request #159 from JJK801/filters
Enabling filter's default parameters in config files

@stof stof merged commit d355798 into doctrine:master Mar 5, 2013

1 check passed

default The Travis build passed
Details

@JJK801 JJK801 deleted the JJK801:filters branch Mar 6, 2013

@trsteel88

This comment has been minimized.

trsteel88 commented Jul 14, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment