3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Server\Reflection
;
13 * Node Tree class for Zend\Server reflection operations
21 protected $value = null;
24 * Array of child nodes (if any)
27 protected $children = array();
30 * Parent node (if any)
31 * @var \Zend\Server\Reflection\Node
33 protected $parent = null;
39 * @param \Zend\Server\Reflection\Node $parent Optional
40 * @return \Zend\Server\Reflection\Node
42 public function __construct($value, Node
$parent = null)
44 $this->value
= $value;
45 if (null !== $parent) {
46 $this->setParent($parent, true);
55 * @param \Zend\Server\Reflection\Node $node
56 * @param bool $new Whether or not the child node is newly created
57 * and should always be attached
60 public function setParent(Node
$node, $new = false)
62 $this->parent
= $node;
65 $node->attachChild($this);
71 * Create and attach a new child node
75 * @return \Zend\Server\Reflection\Node New child node
77 public function createChild($value)
79 $child = new static($value, $this);
87 * @param \Zend\Server\Reflection\Node $node
90 public function attachChild(Node
$node)
92 $this->children
[] = $node;
94 if ($node->getParent() !== $this) {
95 $node->setParent($this);
100 * Return an array of all child nodes
104 public function getChildren()
106 return $this->children
;
110 * Does this node have children?
114 public function hasChildren()
116 return count($this->children
) > 0;
120 * Return the parent node
122 * @return null|\Zend\Server\Reflection\Node
124 public function getParent()
126 return $this->parent
;
130 * Return the node's current value
134 public function getValue()
142 * @param mixed $value
145 public function setValue($value)
147 $this->value
= $value;
151 * Retrieve the bottommost nodes of this node's tree
153 * Retrieves the bottommost nodes of the tree by recursively calling
154 * getEndPoints() on all children. If a child is null, it returns the parent
159 public function getEndPoints()
161 $endPoints = array();
162 if (!$this->hasChildren()) {
166 foreach ($this->children
as $child) {
167 $value = $child->getValue();
169 if (null === $value) {
170 $endPoints[] = $this;
171 } elseif ((null !== $value) && $child->hasChildren()) {
172 $childEndPoints = $child->getEndPoints();
173 if (!empty($childEndPoints)) {
174 $endPoints = array_merge($endPoints, $childEndPoints);
176 } elseif ((null !== $value) && !$child->hasChildren()) {
177 $endPoints[] = $child;