EntityVisitor.php 1.24 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php

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

namespace Irstea\PlantUmlBundle\Model\Orm;

use Doctrine\ORM\Mapping\ClassMetadata;
use Irstea\PlantUmlBundle\Model\ClassVisitor;

/**
 * Description of Visitor
 *
 * @author Guillaume Perréal <guillaume.perreal@irstea.fr>
 */
class EntityVisitor extends ClassVisitor
{
    /**
     * @var ClassMetadata[]
     */
    protected $metadata = [];

26
    public function __construct(array $metadata, \Irstea\PlantUmlBundle\Model\ClassFilterInterface $filter = null)
27
    {
28
        parent::__construct($filter);
29

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
        foreach($metadata as $md) {
            /* @var $md ClassMetadata */
            $this->metadata[$md->getReflectionClass()->getName()] = $md;
        }
    }

    public function doVisitClass($className)
    {
        if (isset($this->metadata[$className])) {
            return $this->visitClassMetadata($this->metadata[$className]);
        }

        return parent::doVisitClass($className);
    }

    /**
     * @param ClassMetadata $metadata
     * @return AbstractNode
     */
    protected function visitClassMetadata(ClassMetadata $metadata)
    {
        return $this->visitClassReflection($metadata->getReflectionClass());
    }
}