BaseNode.php 2.73 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
use Irstea\PlantUmlBundle\Model\NodeInterface;
12
use Irstea\PlantUmlBundle\Writer\WriterInterface;
13
14
15
16
17
18

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

26
27
28
29
30
    /**
     * @var string
     */
    private $alias;

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

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

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

Guillaume Perréal's avatar
Guillaume Perréal committed
46
47
48
49
50
    /**
     * @var int
     */
    private $ordering;

51
52
53
54
55
56
    /**
     * @param string $name
     * @param string $nodeType
     * @param array $classifiers
     * @param array $stereotypes
     */
Guillaume Perréal's avatar
Guillaume Perréal committed
57
    function __construct($name, $nodeType, array $classifiers = [], array $stereotypes = [], $ordering = 0)
58
    {
59
60
61
62
        $pos = strrpos($name, '\\');
        $this->name        = substr($name, $pos + 1);
        $this->alias       = str_replace('\\', '.', $name)."_node";

63
64
65
        $this->nodeType    = $nodeType;
        $this->classifiers = $classifiers;
        $this->stereotypes = $stereotypes;
Guillaume Perréal's avatar
Guillaume Perréal committed
66
        $this->ordering    = $ordering;
67
68
    }

69
    public function outputTo(WriterInterface $writer)
70
    {
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
        $this
            ->outputClassifiersTo($writer)
            ->outputNodeTypeTo($writer);
        $writer->printf('"%s" as %s', $this->name, $this->alias);
        $this
            ->outputStereotypesTo($writer);
        $writer
            ->write(" {\n")
            ->indent();
        $this
            ->outputAttributesTo($writer)
            ->outputMethodsTo($writer);
        $writer
            ->dedent()
            ->write("}\n");
        return $this;
87
88
    }

89
    public function outputAliasTo(WriterInterface $writer)
90
    {
91
92
        $writer->write($this->alias);
        return $this;
93
94
    }

95
    protected function outputClassifiersTo(WriterInterface $writer)
96
97
    {
        foreach($this->classifiers as $classifier) {
98
            $writer->printf('%s ', $classifier);
99
        }
100
        return $this;
101
102
    }

103
    protected function outputNodeTypeTo(WriterInterface $writer)
104
    {
105
106
        $writer->printf('%s ', $this->nodeType);
        return $this;
107
108
    }

109
    protected function outputStereotypesTo(WriterInterface $writer)
110
    {
111
112
        foreach($this->stereotypes as $stereotype) {
            $writer->printf(' <<%s>>', $stereotype);
113
        }
114
        return $this;
115
116
    }

117
    protected function outputAttributesTo(WriterInterface $writer)
118
    {
119
        return $this;
120
121
    }

122
    protected function outputMethodsTo(WriterInterface $writer)
123
    {
124
        return $this;
125
126
    }
}