CompositeDecorator.php 1.15 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
 */

namespace Irstea\PlantUmlBundle\Model\Decorator;

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

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

    public function __construct(array $decorators = [])
    {
        $this->decorators = $decorators;
    }

    public function addDecorator(DecoratorInterface $decorator)
    {
        $this->decorators[] = $decorator;
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
32

33
34
35
        return $this;
    }

36
    public function decorate(ReflectionClass $class, NodeInterface $node, ClassVisitorInterface $visitor)
37
    {
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
38
        foreach ($this->decorators as $decorator) {
39
            $decorator->decorate($class, $node, $visitor);
40
        }
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
41

42
43
        return $this;
    }
44
45
46

    public function toConfig(array &$conf)
    {
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
47
        foreach ($this->decorators as $decorator) {
48
49
50
            $decorator->toConfig($conf);
        }
    }
51
}