Source of file FilterChain.php

Size: 1,200 Bytes - Last Modified: 2015-12-22T09:12:14-05:00

../src/FilterChain.php

1234567891011121314151617181920212223242526272829303132333435363738394041
Covered by 8 test(s):
  • MvcLite\CacheTest::testGetCacheKey with data set "simple testing"
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\FilterChainTest::testAddFilter with data set "simple test"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
  • MvcLite\FilterChainTraitsTest::testGetFilterChain
4243
Covered by 8 test(s):
  • MvcLite\CacheTest::testGetCacheKey with data set "simple testing"
  • MvcLite\DispatcherTest::testDispatch with data set "good controller request"
  • MvcLite\DispatcherTest::testDispatch with data set "bad controller request"
  • MvcLite\FilterChainTest::testAddFilter with data set "simple test"
  • MvcLite\RequestTest::testGetContentType with data set "has content type text/plain"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
  • MvcLite\RequestTest::testGetContentType with data set "has nothing"
  • MvcLite\FilterChainTraitsTest::testGetFilterChain
4445464748495051525354
Covered by 3 test(s):
  • MvcLite\CacheTest::testGetCacheKey with data set "simple testing"
  • MvcLite\FilterChainTest::testFilter with data set "simple test"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
55
Covered by 3 test(s):
  • MvcLite\CacheTest::testGetCacheKey with data set "simple testing"
  • MvcLite\FilterChainTest::testFilter with data set "simple test"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
56
Covered by 3 test(s):
  • MvcLite\CacheTest::testGetCacheKey with data set "simple testing"
  • MvcLite\FilterChainTest::testFilter with data set "simple test"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
5758
Covered by 3 test(s):
  • MvcLite\CacheTest::testGetCacheKey with data set "simple testing"
  • MvcLite\FilterChainTest::testFilter with data set "simple test"
  • MvcLite\RequestTest::testGetContentType with data set "has no content type, but has accept headers"
596061
<?php
/**
 * Base Filter
 *
 * @category    MvcLite
 * @package     Lib
 * @subpackage  Filter
 * @since       File available since release 1.0.1
 * @author      Cory Collier <corycollier@corycollier.com>
 */

namespace MvcLite;

/**
 * Base Filter
 *
 * @category    MvcLite
 * @package     Lib
 * @subpackage  Filter
 * @since       Class available since release 1.0.1
 * @author      Cory Collier <corycollier@corycollier.com>
 */
class FilterChain extends ObjectAbstract
{
    const MSG_ERR_FILTER_NOT_FOUND = "Requested filter [%s] not found";

    /**
     * holds the list of filters
     *
     * @var array
     */
    protected $filters = [];

    /**
     * adds a filter to the chain
     *
     * @param \MvcLite\FilterAbstract $filter
     */
    public function addFilter(FilterAbstract $filter)
    {
        $this->filters[] = $filter;

        return $this;
    }

    /**
     * filters a chain
     *
     * @param string $word
     */
    public function filter($word = '')
    {
        // iterate through the filters, triming the word as defined
        foreach ($this->filters as $filter) {
            $word = $filter->filter($word);
        }

        return $word;
    }
}