FilteringDecorator.php 1.24 KB
Newer Older
1
<?php declare(strict_types=1);
2
/*
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
3
4
 * Copyright (C) 2016-2017 IRSTEA
 * All rights reserved.
5
6
7
8
9
10
11
12
 */

namespace Irstea\PlantUmlBundle\Model\Decorator;

use Irstea\PlantUmlBundle\Model\ClassFilterInterface;
use Irstea\PlantUmlBundle\Model\ClassVisitorInterface;
use Irstea\PlantUmlBundle\Model\DecoratorInterface;
use Irstea\PlantUmlBundle\Model\NodeInterface;
13
use ReflectionClass;
14
15

/**
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
16
 * Description of FilteringDecorator.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 */
class FilteringDecorator implements DecoratorInterface
{
    /**
     * @var DecoratorInterface
     */
    private $next;

    /**
     * @var ClassFilterInterface
     */
    private $filter;

    /**
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
31
     * @param DecoratorInterface   $next
32
33
34
35
     * @param ClassFilterInterface $filter
     */
    public function __construct(DecoratorInterface $next, ClassFilterInterface $filter)
    {
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
36
        $this->next = $next;
37
38
39
        $this->filter = $filter;
    }

40
    public function decorate(ReflectionClass $class, NodeInterface $node, ClassVisitorInterface $visitor)
41
    {
42
43
        if ($this->filter->accept($class)) {
            $this->next->decorate($class, $node, $visitor);
44
        }
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
45

46
47
        return $this;
    }
48
49
50
51
52
53

    public function toConfig(array &$conf)
    {
        $this->filter->toConfig($conf);
        $this->next->toConfig($conf);
    }
54
}