| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 10 /** 11 * Base class for runtime components.<br /> 12 * Note that components that output XML tags should not inherit directly from 13 * WactRuntimeComponent but rather the child WactRuntimeTagComponent<br /> 14 * Note that in the comments for this class, the terms parent and child 15 * refer to the given components relative position in a template's 16 * hierarchy, not to the PHP class hierarchy 17 * @package wact 18 * @version $Id: WactRuntimeComponent.class.php 5945 2007-06-06 08:31:43Z pachanga $ 19 */ 20 class WactRuntimeComponent 21 { 22 // can make it protected since used in generated template (see WactRuntimeComponentTag) 23 public $children = array(); 24 25 protected $parent; 26 27 protected $id; 28 29 function __construct($id) 30 { 31 $this->id = $id; 32 } 33 34 function getId() 35 { 36 return $this->id; 37 } 38 39 /** 40 * Returns a child component given it's ID.<br /> 41 * Note this is a potentially expensive operation if dealing with 42 * many components, as it calls the findChild method of children 43 * based on alphanumeric order: strcasecmp(). Attempt to call it via 44 * the nearest known component to the required child. 45 */ 46 function findChild($ServerId) 47 { 48 foreach(array_keys($this->children) as $key) 49 { 50 if (strcasecmp($key, $ServerId)) 51 { 52 if ($result = $this->children[$key]->findChild($ServerId)) 53 return $result; 54 } 55 else 56 return $this->children[$key]; 57 } 58 return FALSE; 59 } 60 61 /** 62 * Same as findChild, except raises error if child is not found 63 */ 64 function getChild($ServerId) 65 { 66 $result = $this->findChild($ServerId); 67 if (!is_object($result)) 68 { 69 throw new WactException('Could not find child component', 70 array('ServerId' => $ServerId, 71 'file' => $this->getRootComponent($this)->getTemplatePath(), 72 'line' => 0)); 73 } 74 return $result; 75 } 76 77 function getRootComponent($item) 78 { 79 if(!$item->parent) 80 return $item; 81 else 82 return $this->getRootComponent($item->parent); 83 } 84 85 function getDatasource() 86 { 87 return parent :: getDatasource(); 88 } 89 90 function getDatasourceComponent() 91 { 92 return parent :: getDatasourceComponent(); 93 } 94 /** 95 * Set the data source of a child component, or raise an error 96 * if the child is not found. 97 */ 98 function setChildDataSource($path, $datasource) 99 { 100 $child = $this->getChild($path); 101 $child->registerDataSource($datasource); 102 } 103 104 function setChildDataSet($path, $datasource) 105 { 106 $child = $this->getChild($path); 107 $child->registerDataSet($datasource); 108 } 109 110 /** 111 * Returns the first child component matching the supplied class name 112 */ 113 function findChildByClass($class) 114 { 115 foreach( array_keys($this->children) as $key) 116 { 117 if (is_a($this->children[$key], $class)) 118 return $this->children[$key]; 119 elseif ($result = $this->children[$key]->findChildByClass($class)) 120 return $result; 121 } 122 return FALSE; 123 } 124 125 /** 126 * Recursively searches through parents of this component searching for a given class name 127 */ 128 function findParentByClass($class) 129 { 130 $parent = $this->parent; 131 while ($parent && !is_a($parent, $class)) 132 $parent = $parent->parent; 133 return $parent; 134 } 135 136 /** 137 * Adds a reference to a child component to this component, using it's 138 * ID attribute as the child array key 139 */ 140 function addChild($child) 141 { 142 $child->parent = $this; 143 $this->children[$child->getId()] = $child; 144 } 145 146 /** 147 * Outputs the component, rendering any child components as well 148 * This method will only ever be called on components that support 149 * Dynamic rendering. 150 */ 151 function render() 152 { 153 foreach(array_keys($this->children) as $key) 154 $this->children[$key]->render(); 155 } 156 } 157 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Dec 1 03:56:46 2008 | Cross-referenced by PHPXref 0.7 |