FieldDecorator.php 1.29 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
28
29
30
31
32
    protected function extractItems(ReflectionClass $class)
    {
        return $this->withMetadata(
            function ($metadata) {
                return $metadata->fieldMappings;
            },
            $class
        );
33
34
    }

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