1: <?php
2: /**
3: * QTag
4: * Code that encapsulates the rendering of an HTML tag. This can be used to render simple tags without the overhead
5: * of the QControl mechanism.
6: *
7: * This class outputs the HTML for one HTML tag, including the attributes inside the tag and the inner html between the
8: * opening and closing tags. If it represents a void element, which is self closing, no inner html or closing tag
9: * will be printed, and the tag will be correctly terminated.
10: *
11: * It will normally print the opening and closing tags on their own lines, with the inner html indented once and in-between
12: * the two tags. If you define the __MINIMIZE__ constant or set QApplication::$Minimize variable, it will all be printed on one line with no indents.
13: *
14: * This control can be used as a drawing aid to draw complex QControls.
15: */
16:
17: class QTag extends QHtmlAttributeManager {
18:
19: /** @var string The tag */
20: protected $strTag;
21: /** @var bool True to render without a closing tag or inner html */
22: protected $blnIsVoidElement = false;
23:
24: /**
25: * @param null|string $strTag
26: * @param bool $blnIsVoidElement
27: * @throws QCallerException
28: */
29:
30: public function __construct($strTag = null, $blnIsVoidElement = false) {
31: if ($strTag) {
32: $this->strTag = $strTag;
33: } elseif (!isset($this->strTag)) {
34: throw new QCallerException ('Must set tag either with subclass or constructor');
35: }
36: $this->blnIsVoidElement = $blnIsVoidElement;
37: }
38:
39: /**
40: * Render the tag and everything between the opening and closing tags. Does this in two modes:
41: * - Developer mode (default) will put the opening and closing tags on separate lines, with the
42: * innerHtml indented in between them.
43: * - Minimize mode (set the __MINIMIZE__ global constant) will put everything on one line, and draw a little faster.
44: * @return string
45: */
46: /**
47: * @param bool $blnDisplayOutput
48: * @param null|string $strInnerText
49: * @param null|array $attributeOverrides
50: * @param null|array $styleOverrides
51: * @return string
52: */
53: protected function render($blnDisplayOutput = true, $strInnerText = null, $attributeOverrides = null, $styleOverrides = null) {
54: if (is_null($strInnerText)) {
55: $strInnerText = $this->getInnerHtml();
56: }
57: $strOut = $this->RenderTag($this->strTag,
58: $attributeOverrides,
59: $styleOverrides,
60: $strInnerText,
61: $this->blnIsVoidElement);
62:
63: if ($blnDisplayOutput) {
64: print ($strOut);
65: return '';
66: } else {
67: return $strOut;
68: }
69: }
70:
71: /**
72: * Returns the html that sits between the tags. Do NOT escape the html, that will be handled at render time.
73: *
74: * This implementation just returns nothing to allow for subclassing. Future implementations could implement
75: * a callback or store text internally.
76: *
77: * @return string
78: */
79: protected function getInnerHtml() {
80: return '';
81: }
82: }
83:
84: