Skip to content

Commit

Permalink
[ZF2-412] FilterChain should allow multiple instances of same type
Browse files Browse the repository at this point in the history
- FilterChain was also not allowing multiple instances of the same
  filter type.
- Additionally, it was using Stdlib\SplPriorityQueue, which does not
  allow for repeat iteration; altered to use Stdlib\PriorityQueue, which
  resolves that issue.
  • Loading branch information
weierophinney committed Jul 26, 2012
1 parent 9d90477 commit 1186963
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
8 changes: 4 additions & 4 deletions library/Zend/Filter/FilterChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Zend\Filter;

use Countable;
use Zend\Stdlib\SplPriorityQueue;
use Zend\Stdlib\PriorityQueue;

/**
* @category Zend
Expand All @@ -32,7 +32,7 @@ class FilterChain extends AbstractFilter implements Countable
/**
* Filter chain
*
* @var SplPriorityQueue
* @var PriorityQueue
*/
protected $filters;

Expand All @@ -42,7 +42,7 @@ class FilterChain extends AbstractFilter implements Countable
*/
public function __construct($options = null)
{
$this->filters = new SplPriorityQueue();
$this->filters = new PriorityQueue();

if (null !== $options) {
$this->setOptions($options);
Expand Down Expand Up @@ -198,7 +198,7 @@ public function merge(FilterChain $filterChain)
/**
* Get all the filters
*
* @return SplPriorityQueue
* @return PriorityQueue
*/
public function getFilters()
{
Expand Down
7 changes: 7 additions & 0 deletions library/Zend/Filter/FilterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ class FilterPluginManager extends AbstractPluginManager
'wordunderscoretoseparator' => 'Zend\Filter\Word\UnderscoreToSeparator',
);

/**
* Whether or not to share by default; default to false
*
* @var bool
*/
protected $shareByDefault = false;

/**
* Validate the plugin
*
Expand Down
1 change: 0 additions & 1 deletion library/Zend/Validator/ValidatorPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ class ValidatorPluginManager extends AbstractPluginManager
'step' => 'Zend\Validator\Step',
);


/**
* Whether or not to share by default; default to false
*
Expand Down
26 changes: 26 additions & 0 deletions tests/Zend/Filter/FilterChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,32 @@ public static function staticUcaseFilter($value)
{
return strtoupper($value);
}

/**
* @group ZF-412
*/
public function testCanAttachMultipleFiltersOfTheSameTypeAsDiscreteInstances()
{
$chain = new FilterChain();
$chain->attachByName('PregReplace', array(
'pattern' => '/Foo/',
'replacement' => 'Bar',
));
$chain->attachByName('PregReplace', array(
'pattern' => '/Bar/',
'replacement' => 'PARTY',
));

$this->assertEquals(2, count($chain));
$filters = $chain->getFilters();
$compare = null;
foreach ($filters as $filter) {
$this->assertNotSame($compare, $filter);
$compare = $filter;
}

$this->assertEquals('Tu et PARTY', $chain->filter('Tu et Foo'));
}
}


Expand Down

0 comments on commit 1186963

Please sign in to comment.