[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Zend Framework 4 * 5 * LICENSE 6 * 7 * This source file is subject to the new BSD license that is bundled 8 * with this package in the file LICENSE.txt. 9 * It is also available through the world-wide-web at this URL: 10 * http://framework.zend.com/license/new-bsd 11 * If you did not receive a copy of the license and are unable to 12 * obtain it through the world-wide-web, please send an email 13 * to [email protected] so we can send you a copy immediately. 14 * 15 * @category Zend 16 * @package Zend_Server 17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 18 * @license http://framework.zend.com/license/new-bsd New BSD License 19 */ 20 21 /** 22 * Node Tree class for Zend_Server reflection operations 23 * 24 * @category Zend 25 * @package Zend_Server 26 * @subpackage Reflection 27 * @version $Id$ 28 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 29 * @license http://framework.zend.com/license/new-bsd New BSD License 30 */ 31 class Zend_Server_Reflection_Node 32 { 33 /** 34 * Node value 35 * @var mixed 36 */ 37 protected $_value = null; 38 39 /** 40 * Array of child nodes (if any) 41 * @var array 42 */ 43 protected $_children = array(); 44 45 /** 46 * Parent node (if any) 47 * @var Zend_Server_Reflection_Node 48 */ 49 protected $_parent = null; 50 51 /** 52 * Constructor 53 * 54 * @param mixed $value 55 * @param Zend_Server_Reflection_Node $parent Optional 56 * @return Zend_Server_Reflection_Node 57 */ 58 public function __construct($value, Zend_Server_Reflection_Node $parent = null) 59 { 60 $this->_value = $value; 61 if (null !== $parent) { 62 $this->setParent($parent, true); 63 } 64 65 return $this; 66 } 67 68 /** 69 * Set parent node 70 * 71 * @param Zend_Server_Reflection_Node $node 72 * @param boolean $new Whether or not the child node is newly created 73 * and should always be attached 74 * @return void 75 */ 76 public function setParent(Zend_Server_Reflection_Node $node, $new = false) 77 { 78 $this->_parent = $node; 79 80 if ($new) { 81 $node->attachChild($this); 82 return; 83 } 84 } 85 86 /** 87 * Create and attach a new child node 88 * 89 * @param mixed $value 90 * @access public 91 * @return Zend_Server_Reflection_Node New child node 92 */ 93 public function createChild($value) 94 { 95 $child = new self($value, $this); 96 97 return $child; 98 } 99 100 /** 101 * Attach a child node 102 * 103 * @param Zend_Server_Reflection_Node $node 104 * @return void 105 */ 106 public function attachChild(Zend_Server_Reflection_Node $node) 107 { 108 $this->_children[] = $node; 109 110 if ($node->getParent() !== $this) { 111 $node->setParent($this); 112 } 113 } 114 115 /** 116 * Return an array of all child nodes 117 * 118 * @return array 119 */ 120 public function getChildren() 121 { 122 return $this->_children; 123 } 124 125 /** 126 * Does this node have children? 127 * 128 * @return boolean 129 */ 130 public function hasChildren() 131 { 132 return count($this->_children) > 0; 133 } 134 135 /** 136 * Return the parent node 137 * 138 * @return null|Zend_Server_Reflection_Node 139 */ 140 public function getParent() 141 { 142 return $this->_parent; 143 } 144 145 /** 146 * Return the node's current value 147 * 148 * @return mixed 149 */ 150 public function getValue() 151 { 152 return $this->_value; 153 } 154 155 /** 156 * Set the node value 157 * 158 * @param mixed $value 159 * @return void 160 */ 161 public function setValue($value) 162 { 163 $this->_value = $value; 164 } 165 166 /** 167 * Retrieve the bottommost nodes of this node's tree 168 * 169 * Retrieves the bottommost nodes of the tree by recursively calling 170 * getEndPoints() on all children. If a child is null, it returns the parent 171 * as an end point. 172 * 173 * @return array 174 */ 175 public function getEndPoints() 176 { 177 $endPoints = array(); 178 if (!$this->hasChildren()) { 179 return $endPoints; 180 } 181 182 foreach ($this->_children as $child) { 183 $value = $child->getValue(); 184 185 if (null === $value) { 186 $endPoints[] = $this; 187 } elseif ((null !== $value) 188 && $child->hasChildren()) 189 { 190 $childEndPoints = $child->getEndPoints(); 191 if (!empty($childEndPoints)) { 192 $endPoints = array_merge($endPoints, $childEndPoints); 193 } 194 } elseif ((null !== $value) && !$child->hasChildren()) { 195 $endPoints[] = $child; 196 } 197 } 198 199 return $endPoints; 200 } 201 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |