1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109:
<?php
namespace Nethgui\Widget\Xhtml;
class TextLabel extends \Nethgui\Widget\XhtmlWidget
{
protected $cssClass = 'TextLabel';
protected function renderContent()
{
$name = $this->getAttribute('name');
$flags = $this->getAttribute('flags');
$hsc = $this->getAttribute('escapeHtml', TRUE);
$tag = $this->getAttribute('tag', 'span');
$template = $this->getAttribute('template', '${0}');
$htmlAttributes = $this->getAttribute('htmlAttributes', array());
$cssClass = $this->cssClass;
if ($this->hasAttribute('class')) {
$cssClass .= ' ' . $this->getAttribute('class');
}
if ($flags & \Nethgui\Renderer\WidgetFactoryInterface::STATE_DISABLED) {
$cssClass .= ' disabled';
}
if ($this->hasAttribute('args')) {
if ( ! is_array($this->getAttribute('args'))) {
throw new \InvalidArgumentException(sprintf('%s: `args` attribute must be an array!', get_class($this)), 1322149926);
}
$args = $this->prepareArgs($this->getAttribute('args'));
} elseif (is_array($this->view[$name])) {
$args = $this->prepareArgs($this->view[$name]);
} else {
$args = array('${0}' => strval($this->view[$name]));
}
$text = '';
if ($this->hasAttribute('name')) {
$cssClass .= ' ' . $this->getClientEventTarget();
}
$viewIsUnobstrusive = $flags & \Nethgui\Renderer\WidgetFactoryInterface::STATE_UNOBTRUSIVE;
if ( ! $viewIsUnobstrusive) {
$text = $hsc ? htmlspecialchars(strtr($template, $args)) : strtr($template, $args);
}
if ($this->hasAttribute('receiver')) {
$attributes['id'] = $this->view->getUniqueId($this->getAttribute('receiver'));
}
$attributes = array_merge($htmlAttributes, array(
'class' => $cssClass,
'data-options' => json_encode(array('template' => $template, 'hsc' => $hsc, 'static' => ! $this->hasAttribute('name')))
));
$content = $this->openTag($tag, $attributes);
$content .= $text;
$content .= $this->closeTag($tag);
return $content;
}
private function prepareArgs($inputArgs)
{
$args = array();
foreach ($inputArgs as $argName => $argValue) {
$args['${' . $argName . '}'] = strval($argValue);
}
return $args;
}
}