Go to the documentation of this file.00001 <?php
00018 abstract class axBaseHelper implements axHelper {
00019
00024 protected $_node_name;
00025
00030 protected $_node_value;
00031
00036 protected $_attributes;
00037
00042 protected $_children;
00043
00051 public function __construct ($node_name, $attributes = array(), $node_value = null) {
00052 $this->_node_name = $node_name;
00053 $this->_node_value = $node_value;
00054 $this->_attributes = $attributes;
00055 }
00056
00061 public function setAttributes ($attributes) {
00062 foreach ($attributes as $key => $value) {
00063 $this->_attributes[$key] = $value;
00064 }
00065 return $this;
00066 }
00067
00071 public function setValue ($value) {
00072 $this->_node_value = $value;
00073 }
00074
00078 public function getValue () {
00079 return $this->_node_value;
00080 }
00081
00092 public function __call ($method, $args) {
00093 if (strpos($method, 'set') === 0) {
00094 $this->_attributes[lcfirst(substr($method, 3))] = $args[0];
00095 }
00096 elseif (strpos($method, 'get') === 0) {
00097 return isset($this->_attributes[lcfirst(substr($method, 3))]) ?
00098 $this->_attributes[lcfirst(substr($method, 3))] : null;
00099 }
00100 return $this;
00101 }
00102
00106 public function appendChild ($node) {
00107 return $this->_children[] = $node;
00108 }
00109
00113 public function prependChild ($node) {
00114 array_unshift($this->_children, $node);
00115 return $this->_children[0];
00116 }
00117
00121 public function __toString () {
00122 $attr = array();
00123 foreach ($this->_attributes as $name => $value) {
00124 $attr[] = "$name=\"$value\"";
00125 }
00126 $node = "<{$this->_node_name} " . implode(' ', $attr);
00127
00128 if (!count($this->_children) && ($this->_node_value === null))
00129 return $node . " />";
00130 else
00131 $node .= ">";
00132
00133 if ($this->_node_value !== null)
00134 $node .= $this->_node_value;
00135
00136 if (count($this->_children))
00137 $node .= implode($this->_children);
00138
00139 return $node . "</{$this->_node_name}>";
00140 }
00141 }
00142
00143 if (!function_exists("lcfirst")) {
00151 function lcfirst ($string) {
00152 $string{0} = strtolower($string{0});
00153 return $string;
00154 }
00155 }