InterfaceDecorator.php 1.5 KB
Newer Older
1
2
<?php
/*
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
13
14
 */

namespace Irstea\PlantUmlBundle\Model\Decorator;

use Irstea\PlantUmlBundle\Model\Arrow\ImplementsInterface;
use Irstea\PlantUmlBundle\Model\ClassVisitorInterface;
use Irstea\PlantUmlBundle\Model\NodeInterface;
use ReflectionClass;

/**
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
15
 * Description of InheritanceDecorator.
16
17
18
19
20
21
22
23
24
 */
class InterfaceDecorator extends AbstractRelationDecorator
{
    public function decorate(ReflectionClass $class, NodeInterface $node, ClassVisitorInterface $visitor)
    {
        $interfaces = $class->getInterfaceNames();

        $indirectInterfaces = array_filter(
            array_map(
Raidelet Nicolas's avatar
Raidelet Nicolas committed
25
26
27
                function ($i) {
                    return $i->getInterfaceNames();
                },
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
                $class->getInterfaces()
            )
        );

        if (!empty($indirectInterfaces)) {
            $indirectInterfaces = call_user_func_array('array_merge', $indirectInterfaces);
            $interfaces = array_diff($interfaces, $indirectInterfaces);
        }

        $parent = $class->getParentClass();
        if ($parent) {
            $interfaces = array_diff($interfaces, $parent->getInterfaceNames());
        }

        $this->visitRelations($node, $interfaces, $visitor);

        return $this;
    }

    protected function buildRelation(NodeInterface $source, NodeInterface $target)
    {
        return new ImplementsInterface($source, $target);
    }
51
52
53
54
55

    public function toConfig(array &$conf)
    {
        $conf['decorators'][] = 'interfaces';
    }
56
}