BaseNode.php 3.31 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
<?php

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

namespace Irstea\PlantUmlBundle\Model\Node;

11
12
use Irstea\PlantUmlBundle\Model\ArrowInterface;
use Irstea\PlantUmlBundle\Model\NamespaceInterface;
13
use Irstea\PlantUmlBundle\Model\NodeInterface;
14
use Irstea\PlantUmlBundle\Writer\WriterInterface;
15
16
17
18
19
20

/**
 * Description of Class
 *
 * @author Guillaume Perréal <guillaume.perreal@irstea.fr>
 */
21
class BaseNode implements NodeInterface
22
23
24
25
{
    /**
     * @var string
     */
26
    private $label;
27

28
29
30
    /**
     * @var string
     */
31
    private $id;
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
    /**
     * @var string
     */
    private $nodeType;

    /**
     * @var string[]
     */
    private $classifiers;

    /**
     * @var string[]
     */
    private $stereotypes;

Guillaume Perréal's avatar
Guillaume Perréal committed
48
    /**
49
     * @var NamespaceInterface
Guillaume Perréal's avatar
Guillaume Perréal committed
50
     */
51
    private $namespace;
Guillaume Perréal's avatar
Guillaume Perréal committed
52

53
    /**
54
     * @param NamespaceInterface $namespace
55
56
     * @param string $id
     * @param string $label
57
58
59
60
     * @param string $nodeType
     * @param array $classifiers
     * @param array $stereotypes
     */
61
    function __construct(NamespaceInterface $namespace, $id, $label, $nodeType, array $classifiers = [], array $stereotypes = [])
62
    {
63
        $this->namespace   = $namespace;
64
65
        $this->id          = $id;
        $this->label       = $label;
66

67
68
69
70
71
        $this->nodeType    = $nodeType;
        $this->classifiers = $classifiers;
        $this->stereotypes = $stereotypes;
    }

72
73
74
75
76
77
78
79
80
81
82
83
    public function addClassifier($classifier)
    {
        $this->classifiers[] = $classifier;
        return $this;
    }

    public function addStereotype($stereotype)
    {
        $this->stereotypes[] = $stereotype;
        return $this;
    }

84
85
86
87
88
89
    public function setLabel($label)
    {
        $this->label = $label;
        return $this;
    }

90
    public function outputTo(WriterInterface $writer)
91
    {
92
93
94
        $this
            ->outputClassifiersTo($writer)
            ->outputNodeTypeTo($writer);
95
        $writer->printf('"%s" as %s', $this->label, $this->id);
96
97
98
99
100
101
102
103
104
105
106
107
        $this
            ->outputStereotypesTo($writer);
        $writer
            ->write(" {\n")
            ->indent();
        $this
            ->outputAttributesTo($writer)
            ->outputMethodsTo($writer);
        $writer
            ->dedent()
            ->write("}\n");
        return $this;
108
109
    }

110
    public function outputAliasTo(WriterInterface $writer)
111
    {
112
        $writer->write($this->id);
113
        return $this;
114
115
    }

116
    protected function outputClassifiersTo(WriterInterface $writer)
117
118
    {
        foreach($this->classifiers as $classifier) {
119
            $writer->printf('%s ', $classifier);
120
        }
121
        return $this;
122
123
    }

124
    protected function outputNodeTypeTo(WriterInterface $writer)
125
    {
126
127
        $writer->printf('%s ', $this->nodeType);
        return $this;
128
129
    }

130
    protected function outputStereotypesTo(WriterInterface $writer)
131
    {
132
133
        foreach($this->stereotypes as $stereotype) {
            $writer->printf(' <<%s>>', $stereotype);
134
        }
135
        return $this;
136
137
    }

138
    protected function outputAttributesTo(WriterInterface $writer)
139
    {
140
        return $this;
141
142
    }

143
    protected function outputMethodsTo(WriterInterface $writer)
144
    {
145
        return $this;
146
    }
147
148
149
150
151
152

    public function addArrow(ArrowInterface $arrow)
    {
        $this->namespace->addArrow($arrow);
        return $this;
    }
153
}