AttributeDecorator.php 1.4 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
15
16
17
 */

namespace Irstea\PlantUmlBundle\Model\Decorator;

use Irstea\PlantUmlBundle\Model\ClassVisitorInterface;
use Irstea\PlantUmlBundle\Model\DecoratorInterface;
use Irstea\PlantUmlBundle\Model\Node\Member\Member;
use Irstea\PlantUmlBundle\Model\Node\Member\MemberInterface;
use Irstea\PlantUmlBundle\Model\NodeInterface;
use ReflectionClass;
use ReflectionProperty;

/**
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
18
 * Description of AttributeDecorator.
19
20
21
22
23
 */
class AttributeDecorator implements DecoratorInterface
{
    public function decorate(ReflectionClass $class, NodeInterface $node, ClassVisitorInterface $visitor)
    {
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
24
        foreach ($class->getProperties() as $property) {
25
            /* @var $property ReflectionProperty */
26
27
28
29
30

            if ($property->getDeclaringClass() != $class) {
                continue;
            }

31
32
33
34
35
36
37
            $node->addAttribute(
                new Member(
                    $property->getName(),
                    false,
                    $property->isPrivate() ? MemberInterface::PRIVATE_ :
                        $property->isProtected() ? MemberInterface::PROTECTED_ :
                            $property->isPublic() ? MemberInterface::PUBLIC_ :
Raidelet Nicolas's avatar
Raidelet Nicolas committed
38
                                MemberInterface::UNKNOWN
39
40
41
42
                )
            );
        }
    }
43
44
45
46
47

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