Graph.php 2.12 KB
Newer Older
1
<?php declare(strict_types=1);
2
/*
Guillaume Perréal's avatar
CS.  
Guillaume Perréal committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * This file is part of "irstea/plantuml-bundle".
 *
 * Copyright (C) 2016-2019 IRSTEA
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License and the GNU
 * Lesser General Public License along with this program. If not, see
 * <https://www.gnu.org/licenses/>.
19 20 21 22 23 24 25 26
 */

namespace Irstea\PlantUmlBundle\Model;

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

/**
Guillaume Perréal's avatar
CS.  
Guillaume Perréal committed
27
 * Description of Graph.
28 29 30 31 32 33 34 35 36 37 38 39 40
 */
class Graph implements GraphInterface
{
    /**
     * @var ClassVisitorInterface
     */
    private $visitor;

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

41 42 43 44 45
    /**
     * Graph constructor.
     * @param ClassVisitorInterface $visitor
     * @param FinderInterface $finder
     */
46 47 48
    public function __construct(ClassVisitorInterface $visitor, FinderInterface $finder)
    {
        $this->visitor = $visitor;
Guillaume Perréal's avatar
CS.  
Guillaume Perréal committed
49
        $this->finder = $finder;
50 51
    }

52 53 54 55
    /**
     *
     */
    public function visitAll(): void
56
    {
Guillaume Perréal's avatar
CS.  
Guillaume Perréal committed
57
        foreach ($this->finder->getIterator() as $class) {
58 59 60 61
            $this->visitor->visitClass($class);
        }
    }

62 63 64 65 66
    /**
     * @param WriterInterface $writer
     * @return $this
     */
    public function writeTo(WriterInterface $writer): self
67 68
    {
        $writer->write("@startuml@\n");
69
        $this->visitor->writeTo($writer);
70
        $writer->write("@enduml@\n");
Guillaume Perréal's avatar
CS.  
Guillaume Perréal committed
71

72 73
        return $this;
    }
74 75 76 77 78 79 80 81 82 83

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