]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/response/html/class_HtmlResponse.php
Continued:
[core.git] / framework / main / classes / response / html / class_HtmlResponse.php
index f0eb0bbb966d280ba877b1f41027edde2fd850cf..5c5beed73b33693a84d647b14b431f1f6f61603d 100644 (file)
@@ -3,7 +3,10 @@
 namespace Org\Mxchange\CoreFramework\Response;
 
 // Import framework stuff
 namespace Org\Mxchange\CoreFramework\Response;
 
 // Import framework stuff
-use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
+use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
+use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
 use Org\Mxchange\CoreFramework\Response\Responseable;
 
 /**
 use Org\Mxchange\CoreFramework\Response\Responseable;
 
 /**
@@ -11,7 +14,7 @@ use Org\Mxchange\CoreFramework\Response\Responseable;
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @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
  *
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -37,7 +40,7 @@ class HtmlResponse extends BaseResponse implements Responseable {
         *
         * @return      void
         */
         *
         * @return      void
         */
-       protected function __construct () {
+       private function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
 
                // Call parent constructor
                parent::__construct(__CLASS__);
 
@@ -58,16 +61,6 @@ class HtmlResponse extends BaseResponse implements Responseable {
                return $responseInstance;
        }
 
                return $responseInstance;
        }
 
-       /**
-        * Initializes the template engine instance
-        *
-        * @param       $applicationInstance    An instance of a manageable application
-        * @return      void
-        */
-       public final function initTemplateEngine (ManageableApplication $applicationInstance) {
-               $this->setTemplateInstance($this->prepareTemplateInstance($applicationInstance));
-       }
-
        /**
         * Adds a cookie to the response
         *
        /**
         * Adds a cookie to the response
         *
@@ -78,35 +71,34 @@ class HtmlResponse extends BaseResponse implements Responseable {
         * @return      void
         * @throws      ResponseHeadersAlreadySentException             If headers are already sent
         * @todo        Encryption of cookie data not yet supported.
         * @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.
         */
         * @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) {
                //* DEBUG: */ echo $cookieName.'='.$cookieValue."<br />\n";
                // Are headers already sent?
                if (headers_sent()) {
                        // Throw an exception here
                        //* DEBUG: */ return;
                        throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT);
                //* DEBUG: */ echo $cookieName.'='.$cookieValue."<br />\n";
                // Are headers already sent?
                if (headers_sent()) {
                        // Throw an exception here
                        //* DEBUG: */ return;
                        throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT);
-               } // END - if
+               }
 
                // Shall we encrypt the cookie?
 
                // Shall we encrypt the cookie?
-               if ($encrypted === true) {
+               if ($encrypted) {
                        // Unsupported at the moment
                        // 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)) {
 
                // 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']))
 
                setcookie($cookieName, $cookieValue, $expires);
                //, $path, $domain, (isset($_SERVER['HTTPS']))
@@ -131,19 +123,19 @@ class HtmlResponse extends BaseResponse implements Responseable {
         */
        public function redirectToConfiguredUrl ($configEntry) {
                // Get application instance
         */
        public function redirectToConfiguredUrl ($configEntry) {
                // Get application instance
-               $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
+               $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);
 
                // 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);
 
                // Get the url from config
 
                // Assign application data
                $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);
 
                // Compile the URL
                $url = $this->getTemplateInstance()->compileRawCode($url);
@@ -153,11 +145,11 @@ class HtmlResponse extends BaseResponse implements Responseable {
                        // Is there a / in front of the relative URL?
                        if (substr($url, 0, 1) == '/') {
                                $url = substr($url, 1);
                        // Is there a / in front of the relative URL?
                        if (substr($url, 0, 1) == '/') {
                                $url = substr($url, 1);
-                       } // END - if
+                       }
 
                        // No, then extend it with our base URL
 
                        // 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('&amp;', '&', $url));
 
                // Add redirect header
                $this->addHeader('Location', str_replace('&amp;', '&', $url));
@@ -181,7 +173,7 @@ class HtmlResponse extends BaseResponse implements Responseable {
         * @param       $cookieName             Cookie to expire
         * @return      void
         */
         * @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
                // Is the cookie there?
                if (isset($_COOKIE[$cookieName])) {
                        // Then expire it with 20 minutes past
@@ -189,7 +181,7 @@ class HtmlResponse extends BaseResponse implements Responseable {
 
                        // Remove it from array
                        unset($_COOKIE[$cookieName]);
 
                        // Remove it from array
                        unset($_COOKIE[$cookieName]);
-               } // END - if
+               }
        }
 
        /**
        }
 
        /**
@@ -198,12 +190,12 @@ class HtmlResponse extends BaseResponse implements Responseable {
         * @param       $cookieName             Cookie to refresh
         * @return      void
         */
         * @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);
                // Only update existing cookies
                if (isset($_COOKIE[$cookieName])) {
                        // Update the cookie
                        $this->addCookie($cookieName, $_COOKIE[$cookieName], false);
-               } // END - if
+               }
        }
 
 }
        }
 
 }