1
0
mirror of synced 2025-01-19 06:51:40 +03:00

Revert "allowed to pass filter objects to the configurator"

This reverts commit a9b4debe37370a4ff30141f8e4c6a444c226e06c. See the
discussion on the original PR:

https://github.com/doctrine/doctrine2/pull/434

Conflicts:
	lib/Doctrine/ORM/Configuration.php
This commit is contained in:
Alexander 2013-02-09 20:27:39 +01:00
parent 3b0a242ab3
commit 9bf501dd25
4 changed files with 13 additions and 43 deletions

View File

@ -635,24 +635,12 @@ class Configuration extends \Doctrine\DBAL\Configuration
/** /**
* Adds a filter to the list of possible filters. * Adds a filter to the list of possible filters.
* *
* @param string $name The name of the filter. * @param string $name The name of the filter.
* @param string|Query\Filter\SQLFilter $filter The filter class name or an SQLFilter instance. * @param string $className The class name of the filter.
*
* @return void
*
* @throws \InvalidArgumentException If the filter is an object and it doesn't
* extend the Query\Filter\SQLFilter class.
*/ */
public function addFilter($name, $filter) public function addFilter($name, $className)
{ {
if (is_object($filter) && ! $filter instanceof Query\Filter\SQLFilter) { $this->_attributes['filters'][$name] = $className;
throw new \InvalidArgumentException(
"A filter can be either a class name or an object extending \Doctrine\ORM\Query\Filter\SQLFilter," .
" instance of '" . get_class($filter) . "' given."
);
}
$this->_attributes['filters'][$name] = $filter;
} }
/** /**
@ -660,10 +648,10 @@ class Configuration extends \Doctrine\DBAL\Configuration
* *
* @param string $name The name of the filter. * @param string $name The name of the filter.
* *
* @return null|string|Query\Filter\SQLFilter The class name of the filter, an * @return string The class name of the filter, or null of it is not
* SQLFilter instance or null of it is not defined. * defined.
*/ */
public function getFilter($name) public function getFilterClassName($name)
{ {
return isset($this->_attributes['filters'][$name]) return isset($this->_attributes['filters'][$name])
? $this->_attributes['filters'][$name] ? $this->_attributes['filters'][$name]

View File

@ -104,14 +104,12 @@ class FilterCollection
*/ */
public function enable($name) public function enable($name)
{ {
if (null === $filter = $this->config->getFilter($name)) { if (null === $filterClass = $this->config->getFilterClassName($name)) {
throw new \InvalidArgumentException("Filter '" . $name . "' does not exist."); throw new \InvalidArgumentException("Filter '" . $name . "' does not exist.");
} }
if (!isset($this->enabledFilters[$name])) { if (!isset($this->enabledFilters[$name])) {
$this->enabledFilters[$name] = is_object($filter) $this->enabledFilters[$name] = new $filterClass($this->em);
? $filter
: new $filter($this->em);
// Keep the enabled filters sorted for the hash // Keep the enabled filters sorted for the hash
ksort($this->enabledFilters); ksort($this->enabledFilters);

View File

@ -230,9 +230,9 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
public function testAddGetFilters() public function testAddGetFilters()
{ {
$this->assertSame(null, $this->configuration->getFilter('NonExistingFilter')); $this->assertSame(null, $this->configuration->getFilterClassName('NonExistingFilter'));
$this->configuration->addFilter('FilterName', __CLASS__); $this->configuration->addFilter('FilterName', __CLASS__);
$this->assertSame(__CLASS__, $this->configuration->getFilter('FilterName')); $this->assertSame(__CLASS__, $this->configuration->getFilterClassName('FilterName'));
} }
public function setDefaultRepositoryClassName() public function setDefaultRepositoryClassName()

View File

@ -58,27 +58,11 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase
public function testConfigureFilter() public function testConfigureFilter()
{ {
$config = new \Doctrine\ORM\Configuration(); $config = new \Doctrine\ORM\Configuration();
$validFilter = $this->getMockBuilder('\Doctrine\ORM\Query\Filter\SQLFilter')
->disableOriginalConstructor()
->getMock();
$config->addFilter("geolocation", $validFilter);
$config->addFilter("locale", "\Doctrine\Tests\ORM\Functional\MyLocaleFilter"); $config->addFilter("locale", "\Doctrine\Tests\ORM\Functional\MyLocaleFilter");
$this->assertEquals("\Doctrine\Tests\ORM\Functional\MyLocaleFilter", $config->getFilter("locale")); $this->assertEquals("\Doctrine\Tests\ORM\Functional\MyLocaleFilter", $config->getFilterClassName("locale"));
$this->assertNull($config->getFilter("foo")); $this->assertNull($config->getFilterClassName("foo"));
$this->assertInstanceOf("\Doctrine\ORM\Query\Filter\SQLFilter", $config->getFilter("geolocation"));
}
/**
* @expectedException InvalidArgumentException
*/
public function testConfigureFilterFails()
{
$config = new \Doctrine\ORM\Configuration();
$invalidFilter = $this->getMock('\StdClass');
$config->addFilter("geolocation", $invalidFilter);
} }
public function testEntityManagerEnableFilter() public function testEntityManagerEnableFilter()