/** * overwrite parents __construct() method as we do not have a lot to do here. * * @param none * @return void * @throws \Thallium\Controllers\ExceptionController */ public function __construct() { if (!\Thallium\Controllers\MainController::inTestMode()) { static::raiseError(__METHOD__ . '(), this view is only valid in test mode!', true); return; } if (!$this->addMode('show')) { static::raiseError(__CLASS__ . '::addMode() returned false!', true); return; } if (!$this->addContent('testcontent')) { static::raiseError(__CLASS__ . '::addContent() returned false!', true); return; } parent::__construct(); return; }
/** * retrieves content snippets from a specific view. * * @param none * @return bool * @throws \Thallium\Controllers\ExceptionController */ protected function rpcGetViewContent() { global $thallium, $router; if (!$router->hasQueryParams() || !$router->hasQueryParam('view') || !$router->hasQueryParam('data') || ($view = $router->getQueryParam('view')) === false || ($data = $router->getQueryParam('data')) === false || empty($view) || !is_string($view) || empty($data) || !is_array($data)) { static::raiseError(__METHOD__ . '(), invalid content-request data!'); return false; } if (!array_key_exists('content', $data) || !isset($data['content']) || empty($data['content']) || !is_string($data['content'])) { static::raiseError(__METHOD__ . '(), $data["content"] is invalid!'); return false; } if (!preg_match('/^[a-z]+$/', strtolower($view))) { static::raiseError(__METHOD__ . '(), $_POST["view"] contains invalid data!'); return false; } if (!preg_match('/^[a-z]+$/', strtolower($data['content']))) { static::raiseError(__METHOD__ . '(), $data["content"] contains invalid data!'); return false; } if (!$thallium->loadController("Templates", "tmpl")) { static::raiseError(__METHOD__ . '(), failed to load TemplatesController!'); return false; } if (($prefix = $thallium->getNamespacePrefix()) === false) { static::raiseError(get_class($thallium) . '::getNamespacePrefix() returned false!'); return false; } if (!isset($prefix) || empty($prefix) || !is_string($prefix)) { static::raiseError(get_class($thallium) . '::getNamespacePrefix() returned no valid data!'); return false; } $view_name = ucwords(strtolower($view)); $view_name = sprintf('\\%s\\Views\\%sView', $prefix, $view_name); try { $view = new $view_name(); } catch (\Exception $e) { static::raiseError(__METHOD__ . "(), failed to load view {$view_name}!", false, $e); return false; } if (!$view->hasContent($data['content'])) { static::raiseError(get_class($view) . '::hasContent() returned false!'); return false; } if (($content = $view->getContent($data['content'], $data)) === false) { static::raiseError(get_class($view) . '::getContent() returned false!'); return false; } if (!isset($content) || empty($content)) { static::raiseError(get_class($view) . '::getContent() returned invalid content!'); return false; } if (\Thallium\Controllers\MainController::inTestMode()) { return $content; } print $content; return true; }
/** * returns all or only the HTTP request header specified by $header. * * @param string * @return string|array|bool * @throws \Thallium\Controllers\ExceptionController */ public function getHttpHeaders($header = null) { // in test mode we are going to fake a JSON content-type. if (\Thallium\Controllers\MainController::inTestMode() and $header === 'Content-Type') { return 'application/json'; } if (!is_null($header) && !is_string($header)) { static::raiseError(__METHOD__ . '(), $header parameter is invalid!'); return false; } if (!isset($this->httpRequestHeaders) || empty($this->httpRequestHeaders)) { return false; } if (is_null($header)) { return $this->httpRequestHeaders; } if (in_array($header, array_keys($this->httpRequestHeaders))) { return $this->httpRequestHeaders[$header]; } return false; }