Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Server / Reflection / Node.php
blob87d788b1b41fd8cf5f32b78596b5cf3de2341aed
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Server\Reflection;
12 /**
13 * Node Tree class for Zend\Server reflection operations
15 class Node
17 /**
18 * Node value
19 * @var mixed
21 protected $value = null;
23 /**
24 * Array of child nodes (if any)
25 * @var array
27 protected $children = array();
29 /**
30 * Parent node (if any)
31 * @var \Zend\Server\Reflection\Node
33 protected $parent = null;
35 /**
36 * Constructor
38 * @param mixed $value
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);
49 return $this;
52 /**
53 * Set parent node
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
58 * @return void
60 public function setParent(Node $node, $new = false)
62 $this->parent = $node;
64 if ($new) {
65 $node->attachChild($this);
66 return;
70 /**
71 * Create and attach a new child node
73 * @param mixed $value
74 * @access public
75 * @return \Zend\Server\Reflection\Node New child node
77 public function createChild($value)
79 $child = new static($value, $this);
81 return $child;
84 /**
85 * Attach a child node
87 * @param \Zend\Server\Reflection\Node $node
88 * @return void
90 public function attachChild(Node $node)
92 $this->children[] = $node;
94 if ($node->getParent() !== $this) {
95 $node->setParent($this);
99 /**
100 * Return an array of all child nodes
102 * @return array
104 public function getChildren()
106 return $this->children;
110 * Does this node have children?
112 * @return bool
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
132 * @return mixed
134 public function getValue()
136 return $this->value;
140 * Set the node value
142 * @param mixed $value
143 * @return void
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
155 * as an end point.
157 * @return array
159 public function getEndPoints()
161 $endPoints = array();
162 if (!$this->hasChildren()) {
163 return $endPoints;
166 foreach ($this->children as $child) {
167 $value = $child->getValue();
169 if (null === $value) {
170 $endPoints[] = $this;
171 } elseif ((null !== $value)
172 && $child->hasChildren())
174 $childEndPoints = $child->getEndPoints();
175 if (!empty($childEndPoints)) {
176 $endPoints = array_merge($endPoints, $childEndPoints);
178 } elseif ((null !== $value) && !$child->hasChildren()) {
179 $endPoints[] = $child;
183 return $endPoints;