|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Platine Framework |
|
5
|
|
|
* |
|
6
|
|
|
* Platine Framework is a lightweight, high-performance, simple and elegant |
|
7
|
|
|
* PHP Web framework |
|
8
|
|
|
* |
|
9
|
|
|
* This content is released under the MIT License (MIT) |
|
10
|
|
|
* |
|
11
|
|
|
* Copyright (c) 2020 Platine Framework |
|
12
|
|
|
* Copyright (c) 2015 JBZoo Content Construction Kit (CCK) |
|
13
|
|
|
* |
|
14
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
15
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
16
|
|
|
* in the Software without restriction, including without limitation the rights |
|
17
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
18
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
19
|
|
|
* furnished to do so, subject to the following conditions: |
|
20
|
|
|
* |
|
21
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
22
|
|
|
* copies or substantial portions of the Software. |
|
23
|
|
|
* |
|
24
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
25
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
26
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
27
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
28
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
29
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
30
|
|
|
* SOFTWARE. |
|
31
|
|
|
*/ |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @file Node.php |
|
35
|
|
|
* |
|
36
|
|
|
* The Graph Node class |
|
37
|
|
|
* |
|
38
|
|
|
* @package Platine\Framework\Helper\Mermaid\Graph |
|
39
|
|
|
* @author Platine Developers Team |
|
40
|
|
|
* @copyright Copyright (c) 2020 |
|
41
|
|
|
* @license http://opensource.org/licenses/MIT MIT License |
|
42
|
|
|
* @link https://www.platine-php.com |
|
43
|
|
|
* @version 1.0.0 |
|
44
|
|
|
* @filesource |
|
45
|
|
|
*/ |
|
46
|
|
|
declare(strict_types=1); |
|
47
|
|
|
|
|
48
|
|
|
namespace Platine\Framework\Helper\Mermaid\Graph; |
|
49
|
|
|
|
|
50
|
|
|
use Stringable; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @class Node |
|
54
|
|
|
* @package Platine\Framework\Helper\Mermaid\Graph |
|
55
|
|
|
*/ |
|
56
|
|
|
class Node implements Stringable |
|
57
|
|
|
{ |
|
58
|
|
|
/** |
|
59
|
|
|
* Constants |
|
60
|
|
|
*/ |
|
61
|
|
|
public const SQUARE = '[%s]'; |
|
62
|
|
|
public const ROUND = '(%s)'; |
|
63
|
|
|
public const CIRCLE = '((%s))'; |
|
64
|
|
|
public const ASYMMETRIC_SHAPE = '>%s]'; |
|
65
|
|
|
public const RHOMBUS = '{%s}'; |
|
66
|
|
|
public const HEXAGON = '{{%s}}'; |
|
67
|
|
|
public const PARALLELOGRAM = '[/%s/]'; |
|
68
|
|
|
public const PARALLELOGRAM_ALT = '[\%s\]'; |
|
69
|
|
|
public const TRAPEZOID = '[/%s\]'; |
|
70
|
|
|
public const TRAPEZOID_ALT = '[\%s/]'; |
|
71
|
|
|
public const DATABASE = '[(%s)]'; |
|
72
|
|
|
public const SUBROUTINE = '[[%s]]'; |
|
73
|
|
|
public const STADIUM = '([%s])'; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* The node id |
|
77
|
|
|
* @var string |
|
78
|
|
|
*/ |
|
79
|
|
|
protected string $id = ''; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* The node title |
|
83
|
|
|
* @var string |
|
84
|
|
|
*/ |
|
85
|
|
|
protected string $title = ''; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* The node form |
|
89
|
|
|
* @var string |
|
90
|
|
|
*/ |
|
91
|
|
|
protected string $form = self::ROUND; |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Create new instance |
|
95
|
|
|
* @param string $id |
|
96
|
|
|
* @param string $title |
|
97
|
|
|
* @param string $form |
|
98
|
|
|
*/ |
|
99
|
|
|
public function __construct( |
|
100
|
|
|
string $id, |
|
101
|
|
|
string $title = '', |
|
102
|
|
|
string $form = self::ROUND |
|
103
|
|
|
) { |
|
104
|
|
|
$this->id = Helper::getId($id); |
|
105
|
|
|
$this->setTitle($title ?: $id); |
|
106
|
|
|
$this->form = $form; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Return the node id |
|
111
|
|
|
* @return string |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getId(): string |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->id; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Set the node title |
|
120
|
|
|
* @param string $title |
|
121
|
|
|
* @return $this |
|
122
|
|
|
*/ |
|
123
|
|
|
public function setTitle(string $title): self |
|
124
|
|
|
{ |
|
125
|
|
|
$this->title = $title; |
|
126
|
|
|
return $this; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Return the string representation |
|
131
|
|
|
* @return string |
|
132
|
|
|
*/ |
|
133
|
|
|
public function __toString(): string |
|
134
|
|
|
{ |
|
135
|
|
|
if (!empty($this->title)) { |
|
136
|
|
|
return $this->id . sprintf( |
|
137
|
|
|
$this->form, |
|
138
|
|
|
Helper::escape($this->title) |
|
139
|
|
|
) . ';'; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
return $this->id . ';'; |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|