FieldDecorator.php 1.55 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\Doctrine;

use Doctrine\ORM\Mapping\ClassMetadata;
use Irstea\PlantUmlBundle\Model\ClassVisitorInterface;
use Irstea\PlantUmlBundle\Model\NodeInterface;
12
use ReflectionClass;
13
14

/**
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
15
 * Description of RelationDecorator.
16
17
18
 */
class FieldDecorator extends AbstractDoctrineDecorator
{
19
    use \Irstea\PlantUmlBundle\Model\Decorator\InheritableItemDecoratorTrait;
20

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

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

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