BaseNode.php 2.38 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
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
39
<?php

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

namespace Irstea\PlantUmlBundle\Model\Node;

use Irstea\PlantUmlBundle\Model\UmlNodeInterface;

/**
 * Description of Class
 *
 * @author Guillaume Perréal <guillaume.perreal@irstea.fr>
 */
class BaseNode implements UmlNodeInterface
{
    /**
     * @var string
     */
    private $name;

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

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

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

Guillaume Perréal's avatar
Guillaume Perréal committed
40
41
42
43
44
    /**
     * @var int
     */
    private $ordering;

45
46
47
48
49
50
    /**
     * @param string $name
     * @param string $nodeType
     * @param array $classifiers
     * @param array $stereotypes
     */
Guillaume Perréal's avatar
Guillaume Perréal committed
51
    function __construct($name, $nodeType, array $classifiers = [], array $stereotypes = [], $ordering = 0)
52
53
54
55
56
    {
        $this->name        = $name;
        $this->nodeType    = $nodeType;
        $this->classifiers = $classifiers;
        $this->stereotypes = $stereotypes;
Guillaume Perréal's avatar
Guillaume Perréal committed
57
        $this->ordering    = $ordering;
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
    }

    public function outputTo($stream)
    {
        $this->outputClassifiersTo($stream);
        $this->outputNodeTypeTo($stream);
        $this->outputAliasTo($stream);
        $this->outputStereotypesTo($stream);
        fputs($stream, " {\n");
        $this->outputAttributesTo($stream);
        $this->outputMethodsTo($stream);
        fputs($stream, "}\n");
    }

    public function outputAliasTo($stream)
    {
74
        fputs($stream, '"'.str_replace('\\', '.', $this->name).'"');
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
    }

    protected function outputClassifiersTo($stream)
    {
        foreach($this->classifiers as $classifier) {
            fputs($stream, "$classifier ");
        }
    }

    protected function outputNodeTypeTo($stream)
    {
        fputs($stream, $this->nodeType." ");
    }

    protected function outputStereotypesTo($stream)
    {
        foreach($this->stereotypes as $stereotypes) {
            fputs($stream, " <<$stereotypes>>");
        }
    }

    protected function outputAttributesTo($stream)
    {
        // NOP
    }

    protected function outputMethodsTo($stream)
    {
        // NOP
    }
Guillaume Perréal's avatar
Guillaume Perréal committed
105
106
107
108
109
110
111
112

    static public function compare(BaseNode $a, BaseNode $b)
    {
        if ($a->ordering === $b->ordering) {
            return strcmp($a->name, $b->name);
        }
        return $a->ordering - $b->ordering;
    }
113
}