FieldDecorator.php 1.48 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php

/*
 * © 2016 IRSTEA
 * Guillaume Perréal <guillaume.perreal@irstea.fr>
 * Tous droits réservés.
 */

namespace Irstea\PlantUmlBundle\Doctrine;

use Doctrine\ORM\Mapping\ClassMetadata;
use Irstea\PlantUmlBundle\Model\ClassVisitorInterface;
use Irstea\PlantUmlBundle\Model\NodeInterface;
14
use ReflectionClass;
15
16
17
18
19
20
21
22

/**
 * Description of RelationDecorator
 *
 * @author Guillaume Perréal <guillaume.perreal@irstea.fr>
 */
class FieldDecorator extends AbstractDoctrineDecorator
{
23
    use \Irstea\PlantUmlBundle\Model\Decorator\InheritableItemDecoratorTrait;
24

25
26
27
    protected function extractItems(ReflectionClass $class)
    {
        return $this->withMetadata(
28
29
            function (ClassMetadata $metadata) {
                /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
30
31
32
33
                return $metadata->fieldMappings;
            },
            $class
        );
34
35
    }

36
    protected function decorateItem(ReflectionClass $class, NodeInterface $node, ClassVisitorInterface $visitor, $field)
37
    {
38
        $isIdentifier = $this->withMetadata(
39
40
            function (ClassMetadata $metadata) use ($field) {
                /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
41
42
43
44
                return $metadata->isIdentifier($field['fieldName']);
            },
            $class
        );
45
46
47
48
        $node->addAttribute(new Field(
            $field['fieldName'],
            $field['type'],
            $field['unique'],
49
50
            $field['nullable'],
            $isIdentifier
51
52
53
        ));
    }
}