array())) { $this->_tagName = $tagName; $this->_tagSelfClosing = $selfClose; $this->_attributes = $attributes; } public function addClass() { foreach (func_get_args() as $class) $this->_attributes['class'][$class] = true; return $this; } public function removeClass($class) { unset($this->_attributes['class'][$class]); return $this; } public function setAttribute($key, $value = null) { $this->_attributes[ $key ] = $value; return $this; } public function __toString() { $attributes = ''; foreach ($this->_attributes as $key => $value) { if (is_array($value)) { // Used for classes. If it's empty, we don't want the attribute at all if (!empty($value)) $value = implode(' ', array_keys($value)); else $value = null; } if ($value === null) continue; if ($key == "icon") continue; $attributes .= ' '. $key; if ($value !== true) $attributes .= '="' . htmlspecialchars($value) . '"'; } if (isset($this->_attributes['icon'])) { $rv = '<'. $this->_tagName . $attributes .'>' . '' . ' ' . htmlspecialchars($this->_attributes['value']); if ($this->_tagName != 'a') { $rv .= '_tagName . '>'; } return $rv; } else { return '<'. $this->_tagName . $attributes . ($this->_tagSelfClosing ? '/' : '') .'>'; } } protected function _setParent(Form_Element $parent) { $this->_parent = $parent; } }