DotsUnited\BundleFu\Filter\FilterChain::addFilter PHP Method

addFilter() public method

Adds a filter to the chain
public addFilter ( DotsUnited\BundleFu\Filter\FilterInterface $filter, string $placement = self::CHAIN_APPEND ) : FilterChain
$filter DotsUnited\BundleFu\Filter\FilterInterface
$placement string
return FilterChain
    public function addFilter(FilterInterface $filter, $placement = self::CHAIN_APPEND)
    {
        if ($placement == self::CHAIN_PREPEND) {
            array_unshift($this->filters, $filter);
        } else {
            $this->filters[] = $filter;
        }
        return $this;
    }

Usage Example

Exemplo n.º 1
0
 public function testFilterOrder()
 {
     $filter = new FilterChain();
     $filter->addFilter(new LowerCase())->addFilter(new StripUpperCase());
     $value = 'AbC';
     $valueExpected = 'abc';
     $this->assertEquals($valueExpected, $filter->filter($value));
     $this->assertEquals($valueExpected, $filter->filterFile($value, '/js/js_1.js', new \SplFileInfo(__DIR__ . '/_files/js/js_1.js'), null, null));
 }