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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
<?php
namespace oroboros\core\abstracts\views;
abstract class AbstractHtmlView extends \oroboros\core\abstracts\views\AbstractView implements \oroboros\core\interfaces\api\HTTPStatusCodeApi {
const CLASS_SCOPE = \oroboros\core\interfaces\api\ClassScopeApi::CLASS_SCOPE_HTML_VIEW;
const CONTENT_TYPE = 'text/html; charset=UTF-8';
const DEFAULT_TEMPLATE = 'install\\InstallTemplate';
const DEFAULT_TEMPLATE_SOURCE = 'system';
private $_headers = array();
private $_meta = array();
private $_css = array();
private $_scripts = array();
private $_fonts = array();
private $_content = array();
private $_template;
private $_template_queue;
public function __construct(array $params = array(), array $flags = array()) {
parent::__construct($params, $flags);
}
public function initialize(array $params = array(), array $flags = array()) {
if (isset($params['template'])) {
$template = $params['template'];
unset($params['template']);
} else {
$template = self::DEFAULT_TEMPLATE;
}
parent::initialize($params, $flags);
$template = $this->_load('template', self::DEFAULT_TEMPLATE_SOURCE, $template, $params, $flags);
$this->_checkTemplate($template);
}
protected function _buildContent(array $params = array(), array $flags = array()) {
$template = $this->_template();
$template->queue($this->_templateData());
$template->render($params, $flags);
}
protected function _template() {
return $this->_template;
}
protected function _resetTemplate() {
$this->_template = $this->_default_template;
}
protected function _checkTemplate($template, array $flags = array()) {
if (is_string($template)) {
try {
$template = $this->_load('template', self::DEFAULT_TEMPLATE_SOURCE, $template, array(), $flags);
if (!($template instanceof \oroboros\core\abstracts\libraries\template\TemplateAbstract)) {
throw new \oroboros\core\utilities\exception\Exception("", self::ERROR_VIEW);
}
$template->initialize(array(), $flags);
$this->_setTemplate($template);
return TRUE;
} catch (\Exception $e) {
$this->_log(SELF::WARNING, "Invalid template supplied to view: [" . $template . "]", array('TRACE' => $e->getTraceAsString()));
return FALSE;
}
} elseif (is_object($template) && ($template instanceof \oroboros\core\abstracts\libraries\template\TemplateAbstract)) {
$template->initialize(array(), $flags);
$this->_setTemplate($template);
return TRUE;
} else {
return FALSE;
}
}
protected function _setTemplate(\oroboros\core\abstracts\libraries\template\TemplateAbstract $template) {
$this->_template = $template;
}
protected function _queueTemplateData(array $params = array(), array $flags = array()) {
foreach ($params as $key => $value) {
$this->_template_queue[$key] = $value;
}
}
protected function _resetTemplateData() {
$this->_template_queue = array();
}
protected function _templateData() {
return $this->_template_queue;
}
protected function _resetScripts() {
$this->_scripts = array();
}
protected function _setScripts(array $scripts) {
foreach ($scripts as $key => $src) {
$this->_scripts[$key] = $src;
}
}
protected function _resetStylesheets() {
$this->_css = array();
}
protected function _setStylesheets(array $stylesheets) {
foreach ($stylesheets as $key => $src) {
$this->_css[$key] = $src;
}
}
protected function _resetMeta() {
$this->_meta = array();
}
protected function _setMeta(array $meta) {
foreach ($meta as $key => $value) {
$this->_meta[$key] = $value;
}
}
protected function _resetFonts() {
$this->_fonts = array();
}
protected function _setFonts(array $fonts) {
foreach ($fonts as $key => $src) {
$this->_fonts[$key] = $src;
}
}
}