Continued:
authorRoland Haeder <roland@mxchange.org>
Fri, 24 Feb 2017 20:48:55 +0000 (21:48 +0100)
committerRoland Haeder <roland@mxchange.org>
Tue, 28 Feb 2017 21:10:04 +0000 (22:10 +0100)
- added missing controller for "tests" application (with own namespace)
- added "import" for BaseController

Signed-off-by: Roland H├Ąder <roland@mxchange.org>
25 files changed:
application/tests/classes/controller/.htaccess [new file with mode: 0644]
application/tests/classes/controller/console/.htaccess [new file with mode: 0644]
application/tests/classes/controller/console/class_TestsConsoleDefaultNewsController.php [new file with mode: 0644]
application/tests/classes/resolver/controller/class_TestsConsoleControllerResolver.php
inc/main/classes/controller/console/class_ConsoleDefaultController.php
inc/main/classes/controller/console/class_ConsoleDefaultNewsController.php
inc/main/classes/controller/html/class_HtmlConfirmController.php
inc/main/classes/controller/html/class_HtmlDefaultController.php
inc/main/classes/controller/html/class_HtmlDefaultNewsController.php
inc/main/classes/controller/html/class_HtmlLoginController.php
inc/main/classes/controller/html/class_HtmlLoginFailedController.php
inc/main/classes/controller/html/class_HtmlLogoutController.php
inc/main/classes/controller/html/class_HtmlLogoutDoneController.php
inc/main/classes/controller/html/class_HtmlProblemController.php
inc/main/classes/controller/html/class_HtmlRegisterController.php
inc/main/classes/controller/html/class_HtmlStatusController.php
inc/main/classes/controller/html/form/class_HtmlDoFormController.php
inc/main/classes/controller/html/login/class_HtmlLoginAreaController.php
inc/main/classes/controller/image/captcha/class_ImageCodeCaptchaController.php
inc/main/classes/controller/image/class_ImageDefaultController.php
inc/main/classes/output/debug/console/class_DebugConsoleOutput.php
inc/main/classes/resolver/controller/class_BaseControllerResolver.php
inc/main/classes/resolver/controller/console/class_ConsoleControllerResolver.php
inc/main/classes/resolver/controller/html/class_HtmlControllerResolver.php
inc/main/classes/resolver/controller/image/class_ImageControllerResolver.php

diff --git a/application/tests/classes/controller/.htaccess b/application/tests/classes/controller/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/tests/classes/controller/console/.htaccess b/application/tests/classes/controller/console/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/tests/classes/controller/console/class_TestsConsoleDefaultNewsController.php b/application/tests/classes/controller/console/class_TestsConsoleDefaultNewsController.php
new file mode 100644 (file)
index 0000000..2f6e415
--- /dev/null
@@ -0,0 +1,143 @@
+<?php
+// Own namespace
+namespace CoreFramework\Tests\Controller;
+
+// Import framework stuff
+use CoreFramework\Controller\BaseController;
+
+/**
+ * The default controller with news for e.g. home or news page
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.shipsimu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class TestsConsoleDefaultNewsController extends BaseController implements Controller {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Init additional filter chains
+               /*
+               foreach (array('bootstrap', 'activation','shutdown') as $filterChain) {
+                       $this->initFilterChain($filterChain);
+               } // END - foreach
+               */
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @param       $resolverInstance               An instance of a command resolver class
+        * @return      $controllerInstance             A prepared instance of this class
+        */
+       public static final function createTestsConsoleDefaultNewsController (CommandResolver $resolverInstance) {
+               // Create the instance
+               $controllerInstance = new TestsConsoleDefaultNewsController();
+
+               // Set the command resolver
+               $controllerInstance->setResolverInstance($resolverInstance);
+
+               // Add news filters to this controller
+               $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_filter'));
+               $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_filter'));
+
+               // Return the prepared instance
+               return $controllerInstance;
+       }
+
+       /**
+        * Handles the given request and response
+        *
+        * @param       $requestInstance        An instance of a request class
+        * @param       $responseInstance       An instance of a response class
+        * @return      void
+        */
+       public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
+               // Get the command instance from the resolver by sending a request instance to the resolver
+               $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
+
+               // Add more filters by the command
+               $commandInstance->addExtraFilters($this, $requestInstance);
+
+               // Run the pre filters
+               $this->executePreFilters($requestInstance, $responseInstance);
+
+               // This request was valid! :-D
+               $requestInstance->requestIsValid();
+
+               // Execute the command
+               $commandInstance->execute($requestInstance, $responseInstance);
+
+               // Run the pre filters
+               $this->executePostFilters($requestInstance, $responseInstance);
+
+               // Flush the response out
+               $responseInstance->flushBuffer();
+       }
+
+       /**
+        * Add a bootstrap filter
+        *
+        * @param       $filterInstance         A Filterable class
+        * @return      void
+        */
+       public function addBootstrapFilter (Filterable $filterInstance) {
+               $this->addFilter('bootstrap', $filterInstance);
+       }
+
+       /**
+        * Executes all bootstrap filters
+        *
+        * @param       $requestInstance        A Requestable class
+        * @param       $responseInstance       A Responseable class
+        * @return      void
+        */
+       public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
+               $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
+       }
+
+       /**
+        * Add a hub activation filter
+        *
+        * @param       $filterInstance         A Filterable class
+        * @return      void
+        */
+       public function addActivationFilter (Filterable $filterInstance) {
+               $this->addFilter('activation', $filterInstance);
+       }
+
+       /**
+        * Executes all hub activation filters
+        *
+        * @param       $requestInstance        A Requestable class
+        * @param       $responseInstance       A Responseable class
+        * @return      void
+        */
+       public function executeActivationFilters (Requestable $requestInstance, Responseable $responseInstance) {
+               $this->executeFilters('activation', $requestInstance, $responseInstance);
+       }
+}
+
+// [EOF]
+?>
index 4a76f17..f5ed6a9 100644 (file)
@@ -1,6 +1,10 @@
 <?php
 // Own namespace
-namespace CoreFramework\Resolver\Controller;
+namespace CoreFramework\Tests\Resolver\Controller;
+
+// Import framework stuff
+use CoreFramework\Controller\BaseController;
+use CoreFramework\Manager\ManageableApplication;
 
 /**
  * A resolver for resolving controllers locally
@@ -55,7 +59,7 @@ class TestsConsoleControllerResolver extends BaseControllerResolver implements C
                if (empty($controllerName)) {
                        // Then thrown an exception here
                        throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
-               } elseif ($resolverInstance->isControllerValid($controllerName) === FALSE) {
+               } elseif ($resolverInstance->isControllerValid(__NAMESPACE__, $controllerName) === FALSE) {
                        // Invalid command found
                        throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
                }
index 08f1505..cd4afa3 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\Default;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Request\Requestable;
 use CoreFramework\Response\Responseable;
 
index a049d1b..2bcca95 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\Default;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Factory\ObjectFactory;
 use CoreFramework\Request\Requestable;
 use CoreFramework\Response\Responseable;
index 4300853..dcdfa84 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\Confirm;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Factory\ObjectFactory;
 use CoreFramework\Response\Responseable;
 
index fc958b8..5fbf4e3 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\Default;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Request\Requestable;
 use CoreFramework\Response\Responseable;
 
index 4f77740..8a793bb 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\News;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Factory\ObjectFactory;
 use CoreFramework\Response\Responseable;
 
index 552c0b6..ddcfb2e 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\Login;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Request\Requestable;
 use CoreFramework\Response\Responseable;
 
index b1c1f7f..a32264a 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\Failed;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Request\Requestable;
 use CoreFramework\Response\Responseable;
 
index 8cd75c3..8d96fb5 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\Logout;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Factory\ObjectFactory;
 use CoreFramework\Request\Requestable;
 use CoreFramework\Response\Responseable;
index 93ea137..4a2fa09 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\Logout;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Request\Requestable;
 
 /**
index 89134f3..de8bbf3 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\Problem;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Request\Requestable;
 use CoreFramework\Response\Responseable;
 
index 194ead9..e6214f6 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\Register;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Response\Responseable;
 
 /**
index c5811bc..59e13bd 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\Status;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Request\Requestable;
 use CoreFramework\Response\Responseable;
 
index e667ec6..d71343b 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\Form;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Request\Requestable;
 use CoreFramework\Response\Responseable;
 
index 7a03eb5..7b4c5d8 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\Login;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Factory\ObjectFactory;
 use CoreFramework\Request\Requestable;
 use CoreFramework\Response\Responseable;
index ddb0d44..a8144ce 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\Image\Captcha;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Factory\ObjectFactory;
 use CoreFramework\Request\Requestable;
 use CoreFramework\Response\Responseable;
index 882e480..37424f9 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Controller\Default;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Request\Requestable;
 use CoreFramework\Response\Responseable;
 
index 8c0a749..3b6dff7 100644 (file)
@@ -66,10 +66,7 @@ class DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStre
                if ($stripTags === TRUE) {
                        // Prepare the output without HTML tags
                        $output = trim(html_entity_decode(strip_tags(stripslashes($output))));
-               } else {
-                       // Prepare the output with HTML tags
-                       $output = trim(stripslashes($output));
-               }
+               } // END - if
 
                // Are debug times enabled?
                if ($this->getConfigInstance()->getConfigEntry('debug_' . self::getResponseTypeFromSystem() . '_output_timings') == 'Y') {
index 13a086a..8f4f024 100644 (file)
@@ -45,20 +45,28 @@ class BaseControllerResolver extends BaseResolver {
         * controller was not found one of the default controllers will be used
         * depending on whether news shall be displayed.
         *
+        * @param       $namespace                              Namespace to look in
         * @param       $controllerName                 A controller name we shall look for
         * @return      $controllerInstance             A loaded controller instance
         * @throws      InvalidControllerException      Thrown if even the requested
         *                                                                              controller class is missing (bad!)
         */
-       protected function loadController ($controllerName) {
+       protected function loadController ($namespace, $controllerName) {
                // Cache default controller
                $defaultController = $this->getConfigInstance()->getConfigEntry('default_' . strtolower($this->getClassPrefix()) . '_controller');
 
                // Init controller instance
                $controllerInstance = NULL;
 
+               // Create full class name
+               $className = sprintf(
+                       '%s\%sDefaultNewsController',
+                       $namespace,
+                       $this->getCapitalizedClassPrefix()
+               );
+
                // Default controller
-               $this->setClassName($this->getCapitalizedClassPrefix() . 'DefaultNewsController');
+               $this->setClassName($className);
 
                // Generate the class name
                //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BEFORE: controller=' . $controllerName);
@@ -70,7 +78,7 @@ class BaseControllerResolver extends BaseResolver {
                        $this->setClassName($className);
                } else {
                        // No news at main controller or non-news controller
-                       $this->setClassName($this->getCapitalizedClassPrefix() . 'DefaultNewsController');
+                       $this->setClassName($className);
                }
                //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('AFTER: controller=' . $this->getClassName());
 
@@ -109,23 +117,39 @@ class BaseControllerResolver extends BaseResolver {
        /**
         * Checks whether the given controller is valid
         *
+        * @param       $namespace                      Namespace to look in, no trailing backslash
         * @param       $controllerName         The default controller we shall execute
         * @return      $isValid                        Whether the given controller is valid
         * @throws      EmptyVariableException          Thrown if given controller is not set
         * @throws      DefaultControllerException      Thrown if default controller was not found
         */
-       public function isControllerValid ($controllerName) {
+       public function isControllerValid ($namespace, $controllerName) {
                // By default nothing shall be valid
                $isValid = FALSE;
 
-               // Is a controller set?
-               if (empty($controllerName)) {
+               // Is namespace and controller name set?
+               if (empty($namespace)) {
+                       // Then thrown an exception here
+                       throw new EmptyVariableException(array($this, 'namespace'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+               } elseif (empty($controllerName)) {
                        // Then thrown an exception here
                        throw new EmptyVariableException(array($this, 'controllerName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
                } // END - if
 
                // Create class name
-               $className = $this->getCapitalizedClassPrefix() . self::convertToClassName($controllerName) . 'Controller';
+               $className = sprintf(
+                       '%s\%sController',
+                       $namespace,
+                       $this->getCapitalizedClassPrefix() . self::convertToClassName($controllerName)
+               );
+               $newsControllerName = sprintf(
+                       '%s\%sDefaultNewsController',
+                       $namespace,
+                       $this->getCapitalizedClassPrefix()
+               );
+
+               // Debug message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('className=%s', $className));
 
                // Now, let us create the full name of the controller class
                $this->setClassName($className);
@@ -136,9 +160,9 @@ class BaseControllerResolver extends BaseResolver {
                        if (class_exists($this->getClassName())) {
                                // This class does exist. :-)
                                $isValid = TRUE;
-                       } elseif ($this->getClassName() != $this->getCapitalizedClassPrefix() . 'DefaultNewsController') {
+                       } elseif ($this->getClassName() != $newsControllerName) {
                                // Set default controller
-                               $this->setClassName($this->getCapitalizedClassPrefix() . 'DefaultNewsController');
+                               $this->setClassName($newsControllerName);
                        } else {
                                // All is tried, give it up here
                                throw new DefaultControllerException($this, self::EXCEPTION_DEFAULT_CONTROLLER_GONE);
@@ -162,11 +186,12 @@ class BaseControllerResolver extends BaseResolver {
                $controllerName = '';
                $controllerInstance = NULL;
 
-               // Get the controller name 
+               // Get namespace and controller name
+               $namespace      = $this->getNamespace();
                $controllerName = $this->getControllerName();
 
                // Get the controller
-               $controllerInstance = $this->loadController($controllerName);
+               $controllerInstance = $this->loadController($namspace, $controllerName);
 
                // And validate it
                if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) {
index dd35543..096a4b1 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Resolver\Controller;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Manager\ManageableApplication;
 
 /**
@@ -44,13 +45,14 @@ class ConsoleControllerResolver extends BaseControllerResolver implements Contro
        /**
         * Creates an instance of a resolver class with a given controller
         *
+        * @param       $namespace                                      Namespace to look in
         * @param       $controllerName                         The controller we shall resolve
         * @param       $applicationInstance            An instance of a manageable application helper class
         * @return      $resolverInstance                       The prepared controller resolver instance
         * @throws      EmptyVariableException          Thrown if default controller is not set
         * @throws      InvalidControllerException      Thrown if default controller is invalid
         */
-       public static final function createConsoleControllerResolver ($controllerName, ManageableApplication $applicationInstance) {
+       public static final function createConsoleControllerResolver ($namespace, $controllerName, ManageableApplication $applicationInstance) {
                // Create the new instance
                $resolverInstance = new ConsoleControllerResolver();
 
@@ -58,7 +60,7 @@ class ConsoleControllerResolver extends BaseControllerResolver implements Contro
                if (empty($controllerName)) {
                        // Then thrown an exception here
                        throw new EmptyVariableException(array($resolverInstance, 'controllerName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
-               } elseif ($resolverInstance->isControllerValid($controllerName) === FALSE) {
+               } elseif ($resolverInstance->isControllerValid($namespace, $controllerName) === FALSE) {
                        // Invalid controller found
                        throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
                }
index 8882dbd..0890dff 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Resolver\Controller;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Manager\ManageableApplication;
 
 /**
@@ -44,13 +45,14 @@ class HtmlControllerResolver extends BaseControllerResolver implements Controlle
        /**
         * Creates an instance of a resolver class with a given controller
         *
+        * @param       $namespace                                      Namespace to look in
         * @param       $controllerName                         The controller we shall resolve
         * @param       $applicationInstance            An instance of a manageable application helper class
         * @return      $resolverInstance                       The prepared controller resolver instance
         * @throws      EmptyVariableException          Thrown if default controller is not set
         * @throws      InvalidControllerException      Thrown if default controller is invalid
         */
-       public static final function createHtmlControllerResolver ($controllerName, ManageableApplication $applicationInstance) {
+       public static final function createHtmlControllerResolver ($namespace, $controllerName, ManageableApplication $applicationInstance) {
                // Create the new instance
                $resolverInstance = new HtmlControllerResolver();
 
@@ -58,7 +60,7 @@ class HtmlControllerResolver extends BaseControllerResolver implements Controlle
                if (empty($controllerName)) {
                        // Then thrown an exception here
                        throw new EmptyVariableException(array($resolverInstance, 'controllerName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
-               } elseif ($resolverInstance->isControllerValid($controllerName) === FALSE) {
+               } elseif ($resolverInstance->isControllerValid($namespace, $controllerName) === FALSE) {
                        // Invalid controller found
                        throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
                }
index 7098713..3863c0e 100644 (file)
@@ -3,6 +3,7 @@
 namespace CoreFramework\Resolver\Controller;
 
 // Import framework stuff
+use CoreFramework\Controller\BaseController;
 use CoreFramework\Manager\ManageableApplication;
 
 /**
@@ -44,13 +45,14 @@ class ImageControllerResolver extends BaseControllerResolver implements Controll
        /**
         * Creates an instance of a resolver class with a given controller
         *
+        * @param       $namespace                                      Namespace to look in
         * @param       $controllerName                         The controller we shall resolve
         * @param       $applicationInstance            An instance of a manageable application helper class
         * @return      $resolverInstance                       The prepared controller resolver instance
         * @throws      EmptyVariableException          Thrown if default controller is not set
         * @throws      InvalidControllerException      Thrown if default controller is invalid
         */
-       public static final function createImageControllerResolver ($controllerName, ManageableApplication $applicationInstance) {
+       public static final function createImageControllerResolver ($namespace, $controllerName, ManageableApplication $applicationInstance) {
                // Create the new instance
                $resolverInstance = new ImageControllerResolver();
 
@@ -58,7 +60,7 @@ class ImageControllerResolver extends BaseControllerResolver implements Controll
                if (empty($controllerName)) {
                        // Then thrown an exception here
                        throw new EmptyVariableException(array($resolverInstance, 'controllerName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
-               } elseif ($resolverInstance->isControllerValid($controllerName) === FALSE) {
+               } elseif ($resolverInstance->isControllerValid($namespace, $controllerName) === FALSE) {
                        // Invalid controller found
                        throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
                }