-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathTree.php
More file actions
69 lines (61 loc) · 1.42 KB
/
Tree.php
File metadata and controls
69 lines (61 loc) · 1.42 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* PHP Command Line Tools
*
* This source file is subject to the MIT license that is bundled
* with this package in the file LICENSE.
*
* @author Ryan Sullivan <rsullivan@connectstudios.com>
* @copyright 2010 James Logsdom (http://girsbrain.org)
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace cli;
/**
* The `Tree` class is used to display data in a tree-like format.
*/
class Tree {
protected $_renderer;
protected $_data = array();
/**
* Sets the renderer used by this tree.
*
* @param tree\Renderer $renderer The renderer to use for output.
* @see tree\Renderer
* @see tree\Ascii
* @see tree\Markdown
*/
public function setRenderer(tree\Renderer $renderer) {
$this->_renderer = $renderer;
}
/**
* Set the data.
* Format:
* [
* 'Label' => [
* 'Thing' => ['Thing'],
* ],
* 'Thing',
* ]
* @param array $data
*/
public function setData(array $data)
{
$this->_data = $data;
}
/**
* Render the tree and return it as a string.
*
* @return string|null
*/
public function render()
{
return $this->_renderer->render($this->_data);
}
/**
* Display the rendered tree
*/
public function display()
{
echo $this->render();
}
}