. */ namespace Irstea\PlantUmlBundle\Model\Filter; use Irstea\PlantUmlBundle\Model\ClassFilterInterface; use ReflectionClass; /** * Description of AbstractListFilter. */ abstract class AbstractListFilter implements ClassFilterInterface { /** * @var string[] */ private $allowed = []; /** * @var bool */ private $notFound; /** * AbstractListFilter constructor. * @param array $allowed * @param bool $notFound */ public function __construct(array $allowed, $notFound = false) { $this->allowed = array_map([$this, 'normalize'], $allowed); $this->notFound = $notFound; } /** * @param ReflectionClass $class * @return bool */ public function accept(ReflectionClass $class) { $tested = $this->normalize($this->extract($class)); foreach ($this->allowed as $reference) { if ($this->matches($tested, $reference)) { return !$this->notFound; } } return $this->notFound; } /** * @param array $conf */ public function toConfig(array &$conf) { $key = $this->notFound ? 'exclude' : 'include'; if (!array_key_exists($key, $conf)) { $conf[$key] = []; } $conf[$key][static::CONF_TYPE] = $this->allowed; } /** * @param string $value * * @return string */ abstract protected function normalize($value): string; /** * @param ReflectionClass $class * * @return string */ abstract protected function extract(ReflectionClass $class): string; /** * @param mixed $tested * @param mixed $reference * * @return bool */ abstract protected function matches($tested, $reference): bool; }