X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Fresponse%2Fimage%2Fclass_ImageResponse.php;h=43a0a7b88b3bb0582b18f07f752b80e46d88308f;hb=refs%2Fheads%2Fmaster;hp=fac49db8af74771f065684927cc34bb1148ad9d0;hpb=146c8b3c929a1b0ab17d6605e5ae949ac44899c1;p=core.git diff --git a/framework/main/classes/response/image/class_ImageResponse.php b/framework/main/classes/response/image/class_ImageResponse.php index fac49db8..783c8489 100644 --- a/framework/main/classes/response/image/class_ImageResponse.php +++ b/framework/main/classes/response/image/class_ImageResponse.php @@ -1,17 +1,21 @@ * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.shipsimu.org * @@ -32,12 +36,17 @@ use CoreFramework\Response\Responseable; * Michal Cihar , licensed under GNU GPL 2.0. */ class ImageResponse extends BaseResponse implements Responseable { + /** + * Instance of the image + */ + private $imageInstance = NULL; + /** * Protected constructor * * @return void */ - protected function __construct () { + private function __construct () { // Call parent constructor parent::__construct(__CLASS__); @@ -59,25 +68,22 @@ class ImageResponse extends BaseResponse implements Responseable { } /** - * Initializes the template engine instance + * Setter for image instance * - * @param $applicationInstance An instance of a manageable application + * @param $imageInstance An instance of an image * @return void */ - public final function initTemplateEngine (ManageableApplication $applicationInstance) { - // Get config instance - $cfg = $this->getConfigInstance(); - - // Set new template engine - $cfg->setConfigEntry('html_template_class' , $cfg->getConfigEntry('image_template_class')); - $cfg->setConfigEntry('raw_template_extension' , '.img'); - $cfg->setConfigEntry('code_template_extension', '.xml'); - $cfg->setConfigEntry('tpl_base_path' , 'templates/images/'); - // @TODO Please fix this - $cfg->setConfigEntry('code_template_type' , 'image'); - - // Get a prepared instance - $this->setTemplateInstance($this->prepareTemplateInstance($applicationInstance)); + public final function setImageInstance (BaseImage $imageInstance) { + $this->imageInstance = $imageInstance; + } + + /** + * Getter for image instance + * + * @return $imageInstance An instance of an image + */ + public final function getImageInstance () { + return $this->imageInstance; } /** @@ -90,33 +96,32 @@ class ImageResponse extends BaseResponse implements Responseable { * @return void * @throws ResponseHeadersAlreadySentException If headers are already sent * @todo Encryption of cookie data not yet supported. - * @todo Why are these parameters conflicting? * @todo If the return statement is removed and setcookie() commented out, * @todo this will send only one cookie out, the first one. */ - public function addCookie ($cookieName, $cookieValue, $encrypted = false, $expires = NULL) { + public function addCookie (string $cookieName, $cookieValue, bool $encrypted = FALSE, int $expires = NULL) { // Are headers already sent? if (headers_sent()) { // Throw an exception here throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); - } // END - if + } // Shall we encrypt the cookie? - if ($encrypted === true) { + if ($encrypted) { // Unsupported at the moment - $this->partialStub('Encryption is unsupported at the moment.'); - } // END - if + DebugMiddleware::getSelfInstance()->partialStub('Encryption is unsupported at the moment.'); + } // For slow browsers set the cookie array element first $_COOKIE[$cookieName] = $cookieValue; // Get all config entries if (is_null($expires)) { - $expires = (time() + $this->getConfigInstance()->getConfigEntry('cookie_expire')); - } // END - if + $expires = (time() + FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('cookie_expire')); + } - $path = $this->getConfigInstance()->getConfigEntry('cookie_path'); - $domain = $this->getConfigInstance()->getConfigEntry('cookie_domain'); + $path = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('cookie_path'); + $domain = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('cookie_domain'); setcookie($cookieName, $cookieValue, $expires); //, $path, $domain, (isset($_SERVER['HTTPS'])) @@ -139,21 +144,21 @@ class ImageResponse extends BaseResponse implements Responseable { * @return void * @throws ResponseHeadersAlreadySentException If headers are already sent */ - public function redirectToConfiguredUrl ($configEntry) { + public function redirectToConfiguredUrl (string $configEntry) { // Get application instance - $applicationInstance = Registry::getRegistry()->getInstance('app'); + $applicationInstance = ApplicationHelper::getSelfInstance(); // Is the header not yet sent? if (headers_sent()) { // Throw an exception here throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); - } // END - if + } // Assign application data - $this->getTemplateInstance()->assignApplicationData($applicationInstance()); + $this->getTemplateInstance()->assignApplicationData($applicationInstance); // Get the url from config - $url = $this->getConfigInstance()->getConfigEntry($configEntry . '_url'); + $url = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($configEntry . '_url'); // Compile the URL $url = $this->getTemplateInstance()->compileRawCode($url); @@ -164,8 +169,8 @@ class ImageResponse extends BaseResponse implements Responseable { if (substr($url, 0, 1) == '/') $url = substr($url, 1); // No, then extend it with our base URL - $url = $this->getConfigInstance()->getConfigEntry('base_url') . '/' . $url; - } // END - if + $url = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('base_url') . '/' . $url; + } // Add redirect header $this->addHeader('Location', str_replace('&', '&', $url)); @@ -190,7 +195,7 @@ class ImageResponse extends BaseResponse implements Responseable { * already sent with an exception * @return void */ - public function flushBuffer ($force = false) { + public function flushBuffer (bool $force = false) { // Finish the image $this->getImageInstance()->finishImage(); @@ -213,7 +218,7 @@ class ImageResponse extends BaseResponse implements Responseable { * @param $cookieName Cookie to expire * @return void */ - public function expireCookie ($cookieName) { + public function expireCookie (string $cookieName) { // Is the cookie there? if (isset($_COOKIE[$cookieName])) { // Then expire it with 20 minutes past @@ -221,7 +226,7 @@ class ImageResponse extends BaseResponse implements Responseable { // Remove it from array unset($_COOKIE[$cookieName]); - } // END - if + } } /** @@ -230,12 +235,12 @@ class ImageResponse extends BaseResponse implements Responseable { * @param $cookieName Cookie to refresh * @return void */ - public function refreshCookie ($cookieName) { + public function refreshCookie (string $cookieName) { // Only update existing cookies if (isset($_COOKIE[$cookieName])) { // Update the cookie $this->addCookie($cookieName, $_COOKIE[$cookieName], false); - } // END - if + } } }