1 | <?php |
||
35 | class Graph |
||
36 | { |
||
37 | /** @var string Name of this graph */ |
||
38 | protected $name = 'G'; |
||
39 | |||
40 | /** @var string Type of this graph; may be digraph, graph or subgraph */ |
||
41 | protected $type = 'digraph'; |
||
42 | |||
43 | /** @var bool If the graph is strict then multiple edges are not allowed between the same pairs of nodes */ |
||
44 | protected $strict = false; |
||
45 | |||
46 | /** @var \phpDocumentor\GraphViz\Attribute[] A list of attributes for this Graph */ |
||
47 | protected $attributes = []; |
||
48 | |||
49 | /** @var \phpDocumentor\GraphViz\Graph[] A list of subgraphs for this Graph */ |
||
50 | protected $graphs = []; |
||
51 | |||
52 | /** @var \phpDocumentor\GraphViz\Node[] A list of nodes for this Graph */ |
||
53 | protected $nodes = []; |
||
54 | |||
55 | /** @var \phpDocumentor\GraphViz\Edge[] A list of edges / arrows for this Graph */ |
||
56 | protected $edges = []; |
||
57 | |||
58 | /** @var string The path to execute dot from */ |
||
59 | protected $path = ''; |
||
60 | |||
61 | /** |
||
62 | * Factory method to instantiate a Graph so that you can use fluent coding |
||
63 | * to chain everything. |
||
64 | * |
||
65 | * @param string $name The name for this graph. |
||
66 | * @param bool $directional Whether this is a directed or undirected graph. |
||
67 | * |
||
68 | * @return \phpDocumentor\GraphViz\Graph |
||
69 | */ |
||
70 | 1 | public static function create($name = 'G', $directional = true) |
|
79 | |||
80 | /** |
||
81 | * Sets the path for the execution. Only needed if it is not in the PATH env. |
||
82 | * |
||
83 | * @param string $path The path to execute dot from |
||
84 | * |
||
85 | * @return \phpDocumentor\GraphViz\Graph |
||
86 | */ |
||
87 | 1 | public function setPath($path) |
|
96 | |||
97 | /** |
||
98 | * Sets the name for this graph. |
||
99 | * |
||
100 | * If this is a subgraph you can prefix the name with _cluster_ to group all |
||
101 | * contained nodes and add a border. |
||
102 | * |
||
103 | * @param string $name The new name for this graph. |
||
104 | * |
||
105 | * @return \phpDocumentor\GraphViz\Graph |
||
106 | */ |
||
107 | 1 | public function setName($name) |
|
112 | |||
113 | /** |
||
114 | * Returns the name for this Graph. |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | 1 | public function getName() |
|
122 | |||
123 | /** |
||
124 | * Sets the type for this graph. |
||
125 | * |
||
126 | * @param string $type Must be either "digraph", "graph" or "subgraph". |
||
127 | * |
||
128 | * @throws \InvalidArgumentException if $type is not "digraph", "graph" or |
||
129 | * "subgraph". |
||
130 | * |
||
131 | * @return \phpDocumentor\GraphViz\Graph |
||
132 | */ |
||
133 | 2 | public function setType($type) |
|
145 | |||
146 | /** |
||
147 | * Returns the type of this Graph. |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | 1 | public function getType() |
|
155 | |||
156 | /** |
||
157 | * Set if the Graph should be strict. If the graph is strict then |
||
158 | * multiple edges are not allowed between the same pairs of nodes |
||
159 | * |
||
160 | * @param bool $isStrict |
||
161 | * |
||
162 | * @return \phpDocumentor\GraphViz\Graph |
||
163 | */ |
||
164 | 2 | public function setStrict($isStrict) |
|
169 | |||
170 | /** |
||
171 | * @return bool |
||
172 | */ |
||
173 | 1 | public function isStrict() |
|
177 | |||
178 | /** |
||
179 | * Magic method to provide a getter/setter to add attributes on the Graph. |
||
180 | * |
||
181 | * Using this method we make sure that we support any attribute without |
||
182 | * too much hassle. If the name for this method does not start with get |
||
183 | * or set we return null. |
||
184 | * |
||
185 | * Set methods return this graph (fluent interface) whilst get methods |
||
186 | * return the attribute value. |
||
187 | * |
||
188 | * @param string $name Name of the method including get/set |
||
189 | * @param mixed[] $arguments The arguments, should be 1: the value |
||
190 | * |
||
191 | * @return \phpDocumentor\GraphViz\Attribute|\phpDocumentor\GraphViz\Graph|null |
||
192 | */ |
||
193 | 1 | public function __call($name, $arguments) |
|
208 | |||
209 | /** |
||
210 | * Adds a subgraph to this graph; automatically changes the type to subgraph. |
||
211 | * |
||
212 | * Please note that an index is maintained using the name of the subgraph. |
||
213 | * Thus if you have 2 subgraphs with the same name that the first will be |
||
214 | * overwritten by the latter. |
||
215 | * |
||
216 | * @param \phpDocumentor\GraphViz\Graph $graph The graph to add onto this graph as |
||
217 | * subgraph. |
||
218 | * |
||
219 | * @see \phpDocumentor\GraphViz\Graph::create() |
||
220 | * |
||
221 | * @return \phpDocumentor\GraphViz\Graph |
||
222 | */ |
||
223 | public function addGraph(\phpDocumentor\GraphViz\Graph $graph) |
||
229 | |||
230 | /** |
||
231 | * Checks whether a graph with a certain name already exists. |
||
232 | * |
||
233 | * @param string $name Name of the graph to find. |
||
234 | * |
||
235 | * @return bool |
||
236 | */ |
||
237 | public function hasGraph($name) |
||
241 | |||
242 | /** |
||
243 | * Returns the subgraph with a given name. |
||
244 | * |
||
245 | * @param string $name Name of the requested graph. |
||
246 | * |
||
247 | * @return \phpDocumentor\GraphViz\Graph |
||
248 | */ |
||
249 | public function getGraph($name) |
||
253 | |||
254 | /** |
||
255 | * Sets a node in the $nodes array; uses the name of the node as index. |
||
256 | * |
||
257 | * Nodes can be retrieved by retrieving the property with the same name. |
||
258 | * Thus 'node1' can be retrieved by invoking: $graph->node1 |
||
259 | * |
||
260 | * @param \phpDocumentor\GraphViz\Node $node The node to set onto this Graph. |
||
261 | * |
||
262 | * @see \phpDocumentor\GraphViz\Node::create() |
||
263 | * |
||
264 | * @return \phpDocumentor\GraphViz\Graph |
||
265 | */ |
||
266 | public function setNode(Node $node) |
||
271 | |||
272 | /** |
||
273 | * Finds a node in this graph or any of its subgraphs. |
||
274 | * |
||
275 | * @param string $name Name of the node to find. |
||
276 | * |
||
277 | * @return \phpDocumentor\GraphViz\Node|null |
||
278 | */ |
||
279 | public function findNode($name) |
||
294 | |||
295 | /** |
||
296 | * Sets a node using a custom name. |
||
297 | * |
||
298 | * @param string $name Name of the node. |
||
299 | * @param \phpDocumentor\GraphViz\Node $value Node to set on the given name. |
||
300 | * |
||
301 | * @see \phpDocumentor\GraphViz\Graph::setNode() |
||
302 | * |
||
303 | * @return \phpDocumentor\GraphViz\Graph |
||
304 | */ |
||
305 | public function __set($name, $value) |
||
310 | |||
311 | /** |
||
312 | * Returns the requested node by its name. |
||
313 | * |
||
314 | * @param string $name The name of the node to retrieve. |
||
315 | * |
||
316 | * @see \phpDocumentor\GraphViz\Graph::setNode() |
||
317 | * |
||
318 | * @return \phpDocumentor\GraphViz\Node|null |
||
319 | */ |
||
320 | public function __get($name) |
||
324 | |||
325 | /** |
||
326 | * Links two nodes to eachother and registers the Edge onto this graph. |
||
327 | * |
||
328 | * @param \phpDocumentor\GraphViz\Edge $edge The link between two classes. |
||
329 | * |
||
330 | * @see \phpDocumentor\GraphViz\Edge::create() |
||
331 | * |
||
332 | * @return \phpDocumentor\GraphViz\Graph |
||
333 | */ |
||
334 | public function link(Edge $edge) |
||
339 | |||
340 | /** |
||
341 | * Exports this graph to a generated image. |
||
342 | * |
||
343 | * This is the only method that actually requires GraphViz. |
||
344 | * |
||
345 | * @param string $type The type to export to; see the link above for a |
||
346 | * list of supported types. |
||
347 | * @param string $filename The path to write to. |
||
348 | * |
||
349 | * @uses GraphViz/dot |
||
350 | * |
||
351 | * @link http://www.graphviz.org/content/output-formats |
||
352 | * |
||
353 | * @throws \phpDocumentor\GraphViz\Exception if an error occurred in GraphViz. |
||
354 | * |
||
355 | * @return \phpDocumentor\GraphViz\Graph |
||
356 | */ |
||
357 | 2 | public function export($type, $filename) |
|
384 | |||
385 | /** |
||
386 | * Generates a DOT file for use with GraphViz. |
||
387 | * |
||
388 | * GraphViz is not used in this method; it is safe to call it even without |
||
389 | * GraphViz installed. |
||
390 | * |
||
391 | * @return string |
||
392 | */ |
||
393 | public function __toString() |
||
417 | } |
||
418 |