1 | <?php |
||
28 | class Node |
||
29 | { |
||
30 | use Attributes; |
||
31 | |||
32 | /** @var string Name for this node */ |
||
33 | protected $name = ''; |
||
34 | |||
35 | /** |
||
36 | * Creates a new node with name and optional label. |
||
37 | * |
||
38 | * @param string $name Name of the new node. |
||
39 | * @param string|null $label Optional label text. |
||
40 | */ |
||
41 | 1 | public function __construct(string $name, ?string $label = null) |
|
50 | |||
51 | /** |
||
52 | * Factory method used to assist with fluent interface handling. |
||
53 | * |
||
54 | * See the examples for more details. |
||
55 | * |
||
56 | * @param string $name Name of the new node. |
||
57 | * @param string|null $label Optional label text. |
||
58 | */ |
||
59 | 1 | public static function create(string $name, ?string $label = null) : self |
|
63 | |||
64 | /** |
||
65 | * Sets the name for this node. |
||
66 | * |
||
67 | * Not to confuse with the label. |
||
68 | * |
||
69 | * @param string $name Name for this node. |
||
70 | */ |
||
71 | 1 | public function setName(string $name) : self |
|
77 | |||
78 | /** |
||
79 | * Returns the name for this node. |
||
80 | */ |
||
81 | 1 | public function getName() : string |
|
85 | |||
86 | /** |
||
87 | * Magic method to provide a getter/setter to add attributes on the Node. |
||
88 | * |
||
89 | * Using this method we make sure that we support any attribute without |
||
90 | * too much hassle. If the name for this method does not start with get or |
||
91 | * set we return null. |
||
92 | * |
||
93 | * Set methods return this graph (fluent interface) whilst get methods |
||
94 | * return the attribute value. |
||
95 | * |
||
96 | * @param string $name Method name; either getX or setX is expected. |
||
97 | * @param mixed[] $arguments List of arguments; only 1 is expected for setX. |
||
98 | * |
||
99 | * @return Attribute|Node|null |
||
100 | * |
||
101 | * @throws AttributeNotFound |
||
102 | */ |
||
103 | 1 | public function __call(string $name, array $arguments) |
|
116 | |||
117 | /** |
||
118 | * Returns the node definition as is requested by GraphViz. |
||
119 | */ |
||
120 | 2 | public function __toString() : string |
|
137 | } |
||
138 |