Namespace_.php 1.38 KB
Newer Older
1
2
3
4
5
6
7
8
<?php

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

9
namespace Irstea\PlantUmlBundle\Model\Namespace_;
10

11
12
use Irstea\PlantUmlBundle\Model\ArrowInterface;
use Irstea\PlantUmlBundle\Model\NamespaceInterface;
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use Irstea\PlantUmlBundle\Writer\WriterInterface;

/**
 * Description of Namespace
 *
 * @author Guillaume Perréal <guillaume.perreal@irstea.fr>
 */
class Namespace_ extends AbstractNamespace
{
    /**
     * @var NamespaceInterface
     */
    private $parent;

    /**
     * @var string
     */
    private $name;

    public function __construct(NamespaceInterface $parent, $name)
    {
        $this->parent = $parent;
        $this->name = $name;
    }

        /**
39
     * @param ArrowInterface $arrow
40
41
     * @return self
     */
42
    public function addArrow(ArrowInterface $arrow)
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    {
        $this->parent->addArrow($arrow);
        return $this;
    }

    /**
     * @param resource WriterInterface $writer
     * @return self
     */
    public function outputTo(WriterInterface $writer)
    {
        if ($this->isEmpty()) {
            return;
        }

        $writer
            ->printf("namespace %s {\n", $this->name)
            ->indent();
        $this
            ->outputNodesTo($writer)
            ->outputChildrenTo($writer);
        $writer
            ->dedent()
            ->write("}\n");

        return $this;
    }
}