Graph.php 1.18 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
12
 */

namespace Irstea\PlantUmlBundle\Model;

use Irstea\PlantUmlBundle\Finder\FinderInterface;
use Irstea\PlantUmlBundle\Writer\WriterInterface;

/**
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
13
 * Description of Graph.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 */
class Graph implements GraphInterface
{
    /**
     * @var ClassVisitorInterface
     */
    private $visitor;

    /**
     * @var FinderInterface
     */
    private $finder;

    public function __construct(ClassVisitorInterface $visitor, FinderInterface $finder)
    {
        $this->visitor = $visitor;
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
30
        $this->finder = $finder;
31
32
33
34
    }

    public function visitAll()
    {
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
35
        foreach ($this->finder->getIterator() as $class) {
36
37
38
39
            $this->visitor->visitClass($class);
        }
    }

40
    public function writeTo(WriterInterface $writer)
41
42
    {
        $writer->write("@startuml@\n");
43
        $this->visitor->writeTo($writer);
44
        $writer->write("@enduml@\n");
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
45

46
47
        return $this;
    }
48
49
50
51
52
53
54
55
56
57

    /**
     * @param array $conf
     */
    public function toConfig(array &$conf)
    {
        $conf['sources'] = [];
        $this->finder->toConfig($conf['sources']);
        $this->visitor->toConfig($conf);
    }
58
}