Namespace_.php 1.57 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
use Irstea\PlantUmlBundle\Writer\WriterInterface;

/**
 * Description of Namespace
 *
 * @author Guillaume Perréal <guillaume.perreal@irstea.fr>
 */
20
class Namespace_ extends AbstractHierachicalNamespace
21
22
{
    /**
23
     * @var AbstractNamespace
24
25
26
27
28
29
30
31
     */
    private $parent;

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

32
    public function __construct(AbstractHierachicalNamespace $parent, $name)
33
34
35
36
37
    {
        $this->parent = $parent;
        $this->name = $name;
    }

38
    /**
39
     * @param ArrowInterface $arrow
40
41
     * @return self
     */
42
    public function addArrow(ArrowInterface $arrow)
43
44
45
46
47
48
    {
        $this->parent->addArrow($arrow);
        return $this;
    }

    /**
49
50
51
52
53
54
55
56
     * @return string
     */
    protected function getNamespacePrefix()
    {
        return $this->parent->getNamespacePrefix() . $this->name . '\\';
    }

        /**
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
     * @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;
    }
}