1<?php
2/*
3 * This file is part of PHPUnit.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11class PHPUnit_Runner_Filter_Factory
12{
13    /**
14     * @var array
15     */
16    private $filters = [];
17
18    /**
19     * @param ReflectionClass $filter
20     * @param mixed           $args
21     */
22    public function addFilter(ReflectionClass $filter, $args)
23    {
24        if (!$filter->isSubclassOf('RecursiveFilterIterator')) {
25            throw new InvalidArgumentException(
26                sprintf(
27                    'Class "%s" does not extend RecursiveFilterIterator',
28                    $filter->name
29                )
30            );
31        }
32
33        $this->filters[] = [$filter, $args];
34    }
35
36    /**
37     * @return FilterIterator
38     */
39    public function factory(Iterator $iterator, PHPUnit_Framework_TestSuite $suite)
40    {
41        foreach ($this->filters as $filter) {
42            list($class, $args) = $filter;
43            $iterator           = $class->newInstance($iterator, $args, $suite);
44        }
45
46        return $iterator;
47    }
48}
49