namespace PFF\HtmlBuilder;
+function escape($text)
+{
+ return htmlspecialchars($text, ENT_COMPAT, 'UTF-8');
+}
+
class Tag
{
private $name, $selfClose, $attributes, $inner=array();
return $this;
}
+ public function toggleAttr($name, $value, $condition)
+ {
+ return $condition
+ ? $this->attr($name, $value)
+ : $this->unsetAttr($name);
+ }
+
+ public function toggleClass($class, $condition)
+ {
+ return $condition
+ ? $this->addClass($class)
+ : $this->removeClass($class);
+ }
+
public function append($item)
{
if (is_array($item)) {
} elseif ($item instanceof Tag) {
$this->inner[] = $item;
} else {
- $this->inner[] = htmlspecialchars($item, ENT_COMPAT, 'UTF-8');
+ $this->inner[] = escape($item);
}
return $this;
}
foreach ($this->attributes as $k => $v) {
if (is_array($v))
$v = implode(' ', $v);
- $s .= ' '.$k.'="'.htmlspecialchars($v, ENT_COMPAT, 'UTF-8').'"';
+ $s .= ' '.$k.'="'.escape($v).'"';
}
$s .= '>';