Source of file Node.php
Size: 4,031 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Server/Reflection/Node.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Server\Reflection; /** * Node Tree class for Zend\Server reflection operations */ class Node { /** * Node value * @var mixed */ protected $value = null; /** * Array of child nodes (if any) * @var array */ protected $children = array(); /** * Parent node (if any) * @var \Zend\Server\Reflection\Node */ protected $parent = null; /** * Constructor * * @param mixed $value * @param \Zend\Server\Reflection\Node $parent Optional * @return \Zend\Server\Reflection\Node */ public function __construct($value, Node $parent = null) { $this->value = $value; if (null !== $parent) { $this->setParent($parent, true); } return $this; } /** * Set parent node * * @param \Zend\Server\Reflection\Node $node * @param bool $new Whether or not the child node is newly created * and should always be attached * @return void */ public function setParent(Node $node, $new = false) { $this->parent = $node; if ($new) { $node->attachChild($this); return; } } /** * Create and attach a new child node * * @param mixed $value * @access public * @return \Zend\Server\Reflection\Node New child node */ public function createChild($value) { $child = new static($value, $this); return $child; } /** * Attach a child node * * @param \Zend\Server\Reflection\Node $node * @return void */ public function attachChild(Node $node) { $this->children[] = $node; if ($node->getParent() !== $this) { $node->setParent($this); } } /** * Return an array of all child nodes * * @return array */ public function getChildren() { return $this->children; } /** * Does this node have children? * * @return bool */ public function hasChildren() { return count($this->children) > 0; } /** * Return the parent node * * @return null|\Zend\Server\Reflection\Node */ public function getParent() { return $this->parent; } /** * Return the node's current value * * @return mixed */ public function getValue() { return $this->value; } /** * Set the node value * * @param mixed $value * @return void */ public function setValue($value) { $this->value = $value; } /** * Retrieve the bottommost nodes of this node's tree * * Retrieves the bottommost nodes of the tree by recursively calling * getEndPoints() on all children. If a child is null, it returns the parent * as an end point. * * @return array */ public function getEndPoints() { $endPoints = array(); if (!$this->hasChildren()) { return $endPoints; } foreach ($this->children as $child) { $value = $child->getValue(); if (null === $value) { $endPoints[] = $this; } elseif ((null !== $value) && $child->hasChildren()) { $childEndPoints = $child->getEndPoints(); if (!empty($childEndPoints)) { $endPoints = array_merge($endPoints, $childEndPoints); } } elseif ((null !== $value) && !$child->hasChildren()) { $endPoints[] = $child; } } return $endPoints; } } |