* @package MCMS\System * @since MCMS 1.0.0 */ class Response { const _VERSION_ = '1.0.0.2'; /** * title of the website */ const META_SITE_TITLE = 'sitetitle'; /** * description of the website */ const META_SITE_DESC = 'sitedesc'; /** * keywords/tags of the website */ const META_SITE_TAGS = 'sitetags'; /** * title of currently selected page */ const META_PAGE_TITLE = 'pagetitle'; /** * description of the currently selected page */ const META_PAGE_DESC = 'pagedesc'; /** * keywords/tags of the currently selected page */ const META_PAGE_TAGS = 'pagedesc'; const ADDON_CSS = 'css'; const ERROR_HTTP = 'http'; const ERROR_CMS = 'cms'; /** * javascript library */ const ADDON_JSLIB = 'jslib'; private $errors = array(); private $type = ''; private $mime = \Mammut\Document\Mime\Mime::TYPE_HTML; private $filename = false; private $addLayout = true; private $media = 'default'; private $meta = [ self::META_SITE_TITLE => 'Unnamed Website', self::META_SITE_DESC => false, self::META_SITE_TAGS => false, self::META_PAGE_TITLE => false, self::META_PAGE_DESC => false, self::META_PAGE_TAGS => false, ]; private $metainfo = null; /** * * @var array content fragments, used by the final layout plugin to generate the page */ private $fragments = array(); /** * * @var mixed the main content, string or \Mammut\IO\iOutput */ private $content = ''; /** * * @var string a new target url */ private $redirectURL = false; private $redirectTarget = false; private $redirectView = false; private $redirectParam = array(); public $addons = [ self::ADDON_CSS => [], self::ADDON_JSLIB => [], ]; /** * * @return int the number of errors in the current run */ public function errorCount() { return count($this->errors); } /** * Add an error to the error log. * If $type is set to ERROR_HTTP, then the error will result in an HTTP error page. In * that case the $code will be used as an HTTP status code. * * @param int $code * error code * @param string $message * the error message * @param string $type * ERROR_CMS or ERROR_HTTP * @param \Exception $e * an optional exception which caused the error */ public function addError($code, $message, $type = self::ERROR_CMS, $e = null) { $this->errors[] = [ 'code' => $code, 'type' => $type, 'message' => $message, 'exception' => $e ]; } public function getErrors() { return $this->errors; } public function clearErrors() { $this->errors = array(); } public function setFragment($key, $value) { $this->fragments[$key] = (string) $value; } public function getFragment($key) { return !empty($this->fragments[$key]) ? $this->fragments[$key] : NULL; } public function getAllFragments() { return $this->fragments; } public function removeFragment($key) { unset($this->fragments[$key]); } public function setMime($mime) { $this->mime = $mime; } public function getMime() { return $this->mime; } public function setFilename($filename) { $this->filename = $filename; } public function getFilename() { return $this->filename; } public function getAddLayout() { return $this->addLayout; } public function setAddLayout($addLayout) { $this->addLayout = $addLayout; } public function getType() { return $this->type; } public function setType($type) { $this->type = $type; } public function getMedia() { return $this->type; } public function setMedia($type) { $type = strtolower($type); switch($type) { case 'default': $this->type = $type; break; default: throw new \InvalidArgumentException($type . ' is not a valid output media (default,popup,small,print)'); break; } } /** * @return mixed */ public function getContent() { return $this->content; } public function setContent($content) { $this->content = $content; } public function appendContent($content) { Logger::getInstance(__CLASS__)->traceStart(); $this->content .= $content; } public function clearContent() { Logger::getInstance(__CLASS__)->traceStart(); $this->content = ''; } /** * defines a new target which should be opened instead of the current one * * @param string $url * the full redirect url */ public function setRedirectURL($url) { Logger::getInstance(__CLASS__)->traceStart(); $this->redirectURL = $url; } /** * Set a redirect target * * @param string $instanceName * the target instance * @param string $view * the target view * @param array $param * optional parameters */ public function setRedirect($instanceName, $view, array $param = array()) { Logger::getInstance(__CLASS__)->traceStart(); $this->redirectTarget = $instanceName; $this->redirectView = $view; $this->redirectParam = $param; } /** * * @return array an array with the redirect parameters or false if none set */ public function getRedirect() { Logger::getInstance(__CLASS__)->traceStart(); if($this->redirectTarget == false && $this->redirectURL == false) return false; return array( 'url' => $this->redirectURL,'instance' => $this->redirectTarget, 'view' => $this->redirectView,'param' => $this->redirectParam); } /** * Fetches a meta setting * * @param string $name * the keyname of the setting * @since 1.0.0.1 * @return multitype:string boolean |boolean */ public function getMeta($name) { Logger::getInstance(__CLASS__)->traceStart(); if(isset($this->meta[$name])) return $this->meta[$name]; return false; } /** * Stores a meta setting * * @param string $name * the keyname of the setting * @param mixed $value * the value * @since 1.0.0.1 */ public function setMeta($name, $value) { Logger::getInstance(__CLASS__)->traceStart(); $this->meta[$name] = $value; } public function getMetainfo() { return $this->metainfo; } public function setMetainfo(Meta $metainfo = null) { $this->metainfo = $metainfo; } /** * Resets the redirect values */ public function clearRedirect() { Logger::getInstance(__CLASS__)->traceStart(); $this->redirectTarget = false; $this->redirectAction = false; $this->redirectParam = false; } }