Image controller/resolver and fixes:
authorRoland Häder <roland@mxchange.org>
Tue, 24 Jun 2008 15:21:28 +0000 (15:21 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 24 Jun 2008 15:21:28 +0000 (15:21 +0000)
- Controller and resolver added for images
- Exceptions fixed in controller and resolver
- No more fall-back on default command if requested command is missing
- Misc constant fixes

21 files changed:
.gitattributes
application/ship-simu/class_ApplicationHelper.php
application/ship-simu/config.php
application/ship-simu/templates/de/code/captch_graphic_code.ctp
inc/classes/exceptions/controller/class_DefaultControllerException.php
inc/classes/exceptions/controller/class_InvalidControllerException.php
inc/classes/exceptions/main/class_ConfigEntryNotFoundException.php
inc/classes/exceptions/main/class_InvalidCommandException.php
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/controller/class_
inc/classes/main/controller/image/.htaccess [new file with mode: 0644]
inc/classes/main/controller/image/class_ImageDefaultController.php [new file with mode: 0644]
inc/classes/main/controller/web/class_WebDefaultController.php
inc/classes/main/resolver/command/image/.htaccess [new file with mode: 0644]
inc/classes/main/resolver/command/image/class_ImageCommandResolver.php [new file with mode: 0644]
inc/classes/main/resolver/command/web/class_WebCommandResolver.php
inc/classes/main/resolver/controller/class_BaseControllerResolver.php
inc/classes/main/resolver/controller/image/.htaccess [new file with mode: 0644]
inc/classes/main/resolver/controller/image/class_ImageControllerResolver.php [new file with mode: 0644]
inc/classes/main/resolver/controller/web/class_WebControllerResolver.php
inc/config.php

index 6eb863342c819ceab083c25b683d73bcfe2d0c6f..bec7301363ab38f0002a54e21f72b4a8962bdb11 100644 (file)
@@ -393,6 +393,8 @@ inc/classes/main/controller/class_BaseController.php -text
 inc/classes/main/controller/form/.htaccess -text
 inc/classes/main/controller/form/class_WebDoFormController.php -text
 inc/classes/main/controller/form/class_WebLoginAreaController.php -text
+inc/classes/main/controller/image/.htaccess -text
+inc/classes/main/controller/image/class_ImageDefaultController.php -text
 inc/classes/main/controller/login/.htaccess -text
 inc/classes/main/controller/login/class_WebLoginAreaController.php -text
 inc/classes/main/controller/web/.htaccess -text
@@ -513,10 +515,14 @@ inc/classes/main/resolver/action/web/class_WebActionResolver.php -text
 inc/classes/main/resolver/class_BaseResolver.php -text
 inc/classes/main/resolver/command/.htaccess -text
 inc/classes/main/resolver/command/class_BaseCommandResolver.php -text
+inc/classes/main/resolver/command/image/.htaccess -text
+inc/classes/main/resolver/command/image/class_ImageCommandResolver.php -text
 inc/classes/main/resolver/command/web/.htaccess -text
 inc/classes/main/resolver/command/web/class_WebCommandResolver.php -text
 inc/classes/main/resolver/controller/.htaccess -text
 inc/classes/main/resolver/controller/class_BaseControllerResolver.php -text
+inc/classes/main/resolver/controller/image/.htaccess -text
+inc/classes/main/resolver/controller/image/class_ImageControllerResolver.php -text
 inc/classes/main/resolver/controller/web/.htaccess -text
 inc/classes/main/resolver/controller/web/class_WebControllerResolver.php -text
 inc/classes/main/response/.htaccess -text
index 370bd0223c7284fe4e98fc7888653bffdedcd3b0..89acb85ea9e952485b64a10e9b12ce92b1637f3d 100644 (file)
@@ -208,7 +208,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica
 
                // If it is null then get default command
                if (is_null($commandName)) {
-                       $commandName = $this->getConfigInstance()->readConfig('default_command');
+                       $commandName = $responseInstance->getDefaultCommand();
                } // END - if
 
                // Get a resolver
@@ -232,7 +232,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica
                // Walk through all messages
                foreach ($messageList as $message) {
                        print("MSG:".$message."<br />\n");
-               }
+               } // END - if
        }
 }
 
index d3d98f7cdb9ecf3d3491325c3a321bc0dcf95020..53dff5c35216497bfc584abe6b94f6a2b560aa94 100644 (file)
 // Get a configuration instance for shorter lines
 $cfg = FrameworkConfiguration::getInstance();
 
-// CFG: DEFAULT-COMMAND
-$cfg->setConfigEntry('default_command', "home");
+// CFG: DEFAULT-WEB-COMMAND
+$cfg->setConfigEntry('default_web_command', "home");
+
+// CFG: DEFAULT-IMAGE-COMMAND
+$cfg->setConfigEntry('default_image_command', "build");
 
 // CFG: PAGE-WITH-NEWS
 $cfg->setConfigEntry('page_with_news', "home");
index 0e044f0b54e70c2ec1f9febd692c31008f99da5d..fbf6f2e64bcd0cdd9c054527a24f9a70de864353 100644 (file)
@@ -9,7 +9,7 @@ $captchaHelper->flushContent();
 // [EOF]
 ?>
 <div class="captcha_image">
-       <img src="$config[base_url]/index.php?app=ship-simu&amp;page=captcha_image&amp;encrypt={?encrypted_code?}&amp;response=image" alt="CAPTCHA-Bild" title="CAPTCHA-Bild" class="captcha_img" />
+       <img src="$config[base_url]/index.php?app=ship-simu&amp;page=code_captcha&amp;encrypt={?encrypted_code?}&amp;response=image" alt="CAPTCHA-Bild" title="CAPTCHA-Bild" class="captcha_img" />
 </div>
 <div class="captcha_code">
        {?captcha_code?}
index 5a93a29cf0c91c520eea73bcd6ecdb4c8ac9f40c..e6be3a107022f814efe2c7951cc6813c9be05b83 100644 (file)
@@ -36,6 +36,9 @@ class DefaultControllerException extends FrameworkException {
                        $this->getLine()
                );
 
+               // Set extra data
+               $this->setExtraData($resolverInstance->getClassName());
+
                // Call parent contructor with message
                parent::__construct($message, $code);
        }
index 4aa54c8e07bdf6266e3695a17ded61e547a36ee0..2546e729c347e31e9e4e11ecbbbca8cc8b768117 100644 (file)
@@ -31,12 +31,16 @@ class InvalidControllerException extends FrameworkException {
         */
        public function __construct(array $msgArray, $code) {
                // Prepare the message
-               $message = sprintf("[%s:%d] Cannot resolve controller <span id=\"exception_reason\">%s</span>.",
+               $message = sprintf("[%s:%d] Cannot resolve controller <span id=\"exception_reason\">%s (class name: %s)</span>.",
                        $msgArray[0]->__toString(),
                        $this->getLine(),
-                       $msgArray[1]
+                       $msgArray[1],
+                       $msgArray[0]->getClassName()
                );
 
+               // Set extra data
+               $this->setExtraData($msgArray[0]->getClassName());
+
                // Call parent contructor with message
                parent::__construct($message, $code);
        }
index 324e991ffe31360056149eedb897c9cc0cadd381..d7d2c958644b36e9c6adae3fcee2241fde803a76 100644 (file)
@@ -37,6 +37,9 @@ class ConfigEntryNotFoundException extends FrameworkException {
                        $classArray[1]
                );
 
+               // Set extra data
+               $this->setExtraData($classArray[1]);
+
                // Call parent constructor
                parent::__construct($message, $code);
        }
index 9a1e9e2ec4b8feaae6f3c4324719f8e46c6dbd8f..dd36dba0c9071773717b9ef6bd48044ae90ef464 100644 (file)
@@ -38,6 +38,9 @@ class InvalidCommandException extends FrameworkException {
                        $msgArray[0]->getClassName()
                );
 
+               // Set extra data
+               $this->setExtraData($msgArray[0]->getClassName());
+
                // Call parent constructor
                parent::__construct($message, $code);
        }
index 5c96b95c0d0ecf5377999fa27ea49b41b259ecce..b49be0347e958253b368d416ad11b529c1390d95 100644 (file)
@@ -146,7 +146,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        const EXCEPTION_MISSING_FILE_IO_HANDLER      = 0x02f;
        const EXCEPTION_MISSING_ELEMENT              = 0x030;
        const EXCEPTION_HEADERS_ALREADY_SENT         = 0x031;
-       const EXCEPTION_DEFAUL_CONTROLLER_GONE       = 0x032;
+       const EXCEPTION_DEFAULT_CONTROLLER_GONE      = 0x032;
        const EXCEPTION_CLASS_NOT_FOUND              = 0x033;
        const EXCEPTION_REQUIRED_INTERFACE_MISSING   = 0x034;
        const EXCEPTION_FATAL_ERROR                  = 0x035;
index 46459d5d8a374b08a709b32a7cdd085216df77f5..d9c2a19a28b33c081827a66d89f3ede7dfd2bfa5 100644 (file)
@@ -21,7 +21,7 @@
  * 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 Controller extends BaseController implements Controller {
+class ???Controller extends BaseController implements Controller {
        /**
         * Protected constructor
         *
@@ -32,13 +32,48 @@ class Controller extends BaseController implements Controller {
                parent::__construct(__CLASS__);
 
                // Set part description
-               $this->setObjectDescription("Ein spezieller Controller");
+               $this->setObjectDescription("");
 
                // Create unique ID number
                $this->generateUniqueId();
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @param       $resolverInstance               An instance of a command resolver class
+        * @return      $controllerInstance             A prepared instance of this class
+        */
+       public final static function create???Controller (CommandResolver $resolverInstance) {
+               // Create the instance
+               $controllerInstance = new ???Controller();
+
+               // Set the command resolver
+               $controllerInstance->setResolverInstance($resolverInstance);
+
+               // 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
+               $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
+
+               // This request was valid! :-D
+               $requestInstance->requestIsValid();
+
+               // Execute the command
+               $commandInstance->execute($requestInstance, $responseInstance);
 
-               // Clean up a little
-               $this->removeSystemArray();
+               // Flush the response out
+               $responseInstance->flushBuffer();
        }
 }
 
diff --git a/inc/classes/main/controller/image/.htaccess b/inc/classes/main/controller/image/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/main/controller/image/class_ImageDefaultController.php b/inc/classes/main/controller/image/class_ImageDefaultController.php
new file mode 100644 (file)
index 0000000..0ff1ec2
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+/**
+ * A default controller for images
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.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 ImageDefaultController extends BaseController implements Controller {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set part description
+               $this->setObjectDescription("Default image controller");
+
+               // Create unique ID number
+               $this->generateUniqueId();
+
+               // Clean up a little
+               $this->removeSystemArray();
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @param       $resolverInstance               An instance of a command resolver class
+        * @return      $controllerInstance             A prepared instance of this class
+        */
+       public final static function createImageDefaultController (CommandResolver $resolverInstance) {
+               // Create the instance
+               $controllerInstance = new ImageDefaultController();
+
+               // Set the command resolver
+               $controllerInstance->setResolverInstance($resolverInstance);
+
+               // 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
+               $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
+
+               // This request was valid! :-D
+               $requestInstance->requestIsValid();
+
+               // Execute the command
+               $commandInstance->execute($requestInstance, $responseInstance);
+
+               // Flush the response out
+               $responseInstance->flushBuffer();
+       }
+}
+
+// [EOF]
+?>
index 7f7e862f8ae24b1e28dcb8f7cf7d6b6bdb3489b6..5a10b0581a21007ed4b11e9b71229ad12a5c1588 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * The default controller for all other requests
+ * The default controller for all other web requests
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
@@ -33,7 +33,7 @@ class WebDefaultController extends BaseController implements Controller {
                parent::__construct(__CLASS__);
 
                // Set part description
-               $this->setObjectDescription("Default controller for all other requests");
+               $this->setObjectDescription("Default controller for all other web requests");
 
                // Create unique ID number
                $this->generateUniqueId();
diff --git a/inc/classes/main/resolver/command/image/.htaccess b/inc/classes/main/resolver/command/image/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/main/resolver/command/image/class_ImageCommandResolver.php b/inc/classes/main/resolver/command/image/class_ImageCommandResolver.php
new file mode 100644 (file)
index 0000000..84e6a26
--- /dev/null
@@ -0,0 +1,184 @@
+<?php
+/**
+ * A command resolver for local (non-hubbed) image commands
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.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 ImageCommandResolver extends BaseCommandResolver implements CommandResolver {
+       /**
+        * Last successfull resolved command
+        */
+       private $lastCommandInstance = null;
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set part description
+               $this->setObjectDescription("Resolver for local image commands");
+
+               // Create unique ID number
+               $this->generateUniqueId();
+
+               // Set prefix to "Image"
+               $this->setCommandPrefix("Image");
+       }
+
+       /**
+        * Creates an instance of a Image command resolver with a given default command
+        *
+        * @param       $commandName                            The default command we shall execute
+        * @param       $appInstance                            An instance of a manageable application helper class
+        * @return      $resolverInstance                       The prepared command resolver instance
+        * @throws      EmptyVariableException          Thrown if the default command is not set
+        * @throws      InvalidCommandException         Thrown if the default command is invalid
+        */
+       public final static function createImageCommandResolver ($commandName, ManageableApplication $appInstance) {
+               // Create the new instance
+               $resolverInstance = new ImageCommandResolver();
+
+               // Is the variable $commandName set and the command is valid?
+               if (empty($commandName)) {
+                       // Then thrown an exception here
+                       throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+               } elseif (!$resolverInstance->isCommandValid($commandName)) {
+                       // Invalid command found
+                       throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND);
+               }
+
+               // Set the application instance
+               $resolverInstance->setApplicationInstance($appInstance);
+
+               // Return the prepared instance
+               return $resolverInstance;
+       }
+
+       /**
+        * Returns an command instance for a given request class or null if
+        * it was not found
+        *
+        * @param       $requestInstance        An instance of a request class
+        * @return      $commandInstance        An instance of the resolved command
+        * @throws      InvalidCommandException                         Thrown if $commandName is
+        *                                                                                              invalid
+        * @throws      InvalidCommandInstanceException         Thrown if $commandInstance
+        *                                                                                              is an invalid instance
+        */
+       public function resolveCommandByRequest (Requestable $requestInstance) {
+               // Init variables
+               $commandName = "";
+               $commandInstance = null;
+
+               // This goes fine so let's resolv the command
+               $commandName = $requestInstance->getRequestElement('page');
+
+               // Is the command empty? Then fall back to default command
+               if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_image_command');
+
+               // Check if the command is valid
+               if (!$this->isCommandValid($commandName)) {
+                       // This command is invalid!
+                       throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
+               } // END - if
+
+               // Get the command
+               $commandInstance = $this->loadCommand($commandName);
+
+               // And validate it
+               if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) {
+                       // This command has an invalid instance!
+                       throw new InvalidCommandInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
+               } // END - if
+
+               // Set last command
+               $this->lastCommandInstance = $commandInstance;
+
+               // Return the resolved command instance
+               return $commandInstance;
+       }
+
+       /**
+        * Resolves the command by its direct name and returns an instance of its class
+        *
+        * @param       $commandName            The direct command name we shall resolve
+        * @return      $commandInstance        An instance of the command class
+        * @throws      InvalidCommandException         Thrown if $commandName is invalid
+        */
+       public function resolveCommand ($commandName) {
+               // Initiate the instance variable
+               $commandInstance = null;
+
+               // Is the command empty? Then fall back to default command
+               if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_image_command');
+
+               // Check if the command is valid
+               if (!$this->isCommandValid($commandName)) {
+                       // This command is invalid!
+                       throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
+               }
+
+               // Get the command
+               $commandInstance = $this->loadCommand($commandName);
+
+               // Return the instance
+               return $commandInstance;
+       }
+
+       /**
+        * "Loads" a given command and instances it if not yet cached
+        *
+        * @param       $commandName                            A command name we shall look for
+        * @return      $commandInstance                        A loaded command instance
+        * @throws      InvalidCommandException         Thrown if even the default
+        *                                                                              command class is missing (bad!)
+        */
+       private function loadCommand ($commandName) {
+               // Cache default command
+               $defaultCommand = $this->getConfigInstance()->readConfig('default_image_command');
+
+               // Init command instance
+               $commandInstance = null;
+
+               // Create command class name
+               $this->setClassName(sprintf("Image%sCommand",
+                       $this->convertToClassName($commandName)
+               ));
+
+               // Is this class loaded?
+               if (!class_exists($this->getClassName())) {
+                       // Class not found, so throw an exception
+                       throw new InvalidCommandException(array($this, $defaultCommand), self::EXCEPTION_INVALID_COMMAND);
+               } // END - if
+
+               // Initiate the command
+               $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
+
+               // Return the result
+               return $commandInstance;
+       }
+}
+
+// [EOF]
+?>
index acb6e52e68d8859e350c8dae7bb35c8d01ac5d8f..9143b730f68c1bb591279a02b536aa6be227a3e5 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * A command resolver for local (non-hubbed) commands
+ * A command resolver for local (non-hubbed) web commands
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
@@ -62,7 +62,7 @@ class WebCommandResolver extends BaseCommandResolver implements CommandResolver
                // Is the variable $commandName set and the command is valid?
                if (empty($commandName)) {
                        // Then thrown an exception here
-                       throw new EmptyVariableException(array($resolverInstance, 'defaultCommand'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+                       throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
                } elseif (!$resolverInstance->isCommandValid($commandName)) {
                        // Invalid command found
                        throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND);
@@ -95,7 +95,7 @@ class WebCommandResolver extends BaseCommandResolver implements CommandResolver
                $commandName = $requestInstance->getRequestElement('page');
 
                // Is the command empty? Then fall back to default command
-               if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_command');
+               if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_web_command');
 
                // Check if the command is valid
                if (!$this->isCommandValid($commandName)) {
@@ -131,7 +131,7 @@ class WebCommandResolver extends BaseCommandResolver implements CommandResolver
                $commandInstance = null;
 
                // Is the command empty? Then fall back to default command
-               if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_command');
+               if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_web_command');
 
                // Check if the command is valid
                if (!$this->isCommandValid($commandName)) {
@@ -156,7 +156,7 @@ class WebCommandResolver extends BaseCommandResolver implements CommandResolver
         */
        private function loadCommand ($commandName) {
                // Cache default command
-               $defaultCommand = $this->getConfigInstance()->readConfig('default_command');
+               $defaultCommand = $this->getConfigInstance()->readConfig('default_web_command');
 
                // Init command instance
                $commandInstance = null;
@@ -168,14 +168,8 @@ class WebCommandResolver extends BaseCommandResolver implements CommandResolver
 
                // Is this class loaded?
                if (!class_exists($this->getClassName())) {
-                       // Class not found, so try the default one or throw exception
-                       if ($commandName != $defaultCommand) {
-                               // Try the default command
-                               return $this->loadCommand($defaultCommand);
-                       } else {
-                               // Still not found?
-                               throw new InvalidCommandException(array($this, $defaultCommand), self::EXCEPTION_INVALID_COMMAND);
-                       }
+                       // Class not found, so throw an exception
+                       throw new InvalidCommandException(array($this, $defaultCommand), self::EXCEPTION_INVALID_COMMAND);
                } // END - if
 
                // Initiate the command
index 1b5fa1c42c2789647ca278e56ec3c122e3225f58..20817453fe9aa3c461e8ac8a165fdf4321df9d6f 100644 (file)
@@ -56,7 +56,7 @@ class BaseControllerResolver extends BaseResolver {
        /**
         * Setter for controller name
         *
-        * @param       $controllerName Last validated controller name
+        * @param       $controllerName         Last validated controller name
         * @return      void
         */
        protected final function setControllerName ($controllerName) {
@@ -68,16 +68,17 @@ class BaseControllerResolver extends BaseResolver {
         *
         * @return      $controllerName Last validated controller name
         */
-       protected final function getControllerName () {
+       public final function getControllerName () {
                return $this->controllerName;
        }
 
        /**
         * Checks wether the given controller is valid
         *
-        * @param       $controllerName The default controller we shall execute
-        * @return      $isValid                Wether the given controller is valid
+        * @param       $controllerName         The default controller we shall execute
+        * @return      $isValid                        Wether the given controller is valid
         * @throws      EmptyVariableException  Thrown if the given controller is not set
+        * @throws      DefaultControllerException      If the default controller was not found
         */
        public function isControllerValid ($controllerName) {
                // By default nothing shall be valid
@@ -112,7 +113,7 @@ class BaseControllerResolver extends BaseResolver {
                                }
                        } else {
                                // All is tried, give it up here
-                               throw new DefaultControllerException($this, self::EXCEPTION_DEFAUL_CONTROLLER_GONE);
+                               throw new DefaultControllerException($this, self::EXCEPTION_DEFAULT_CONTROLLER_GONE);
                        }
                } // END - while
 
diff --git a/inc/classes/main/resolver/controller/image/.htaccess b/inc/classes/main/resolver/controller/image/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/main/resolver/controller/image/class_ImageControllerResolver.php b/inc/classes/main/resolver/controller/image/class_ImageControllerResolver.php
new file mode 100644 (file)
index 0000000..9b982f8
--- /dev/null
@@ -0,0 +1,173 @@
+<?php
+/**
+ * A resolver for resolving controllers locally
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.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 ImageControllerResolver extends BaseControllerResolver implements ControllerResolver {
+       /**
+        * Last successfull resolved controller (name)
+        */
+       private $lastControllerName = "";
+
+       /**
+        * Last successfull resolved controller (instance)
+        */
+       private $lastControllerInstance = null;
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set part description
+               $this->setObjectDescription("Resolver for local web controllers");
+
+               // Create unique ID number
+               $this->generateUniqueId();
+
+               // Set prefix to "Image"
+               $this->setControllerPrefix("Image");
+       }
+
+       /**
+        * Creates an instance of a resolver class with a given command
+        *
+        * @param       $controllerName                         The controller we shall resolve
+        * @param       $appInstance                            An instance of a manageable application helper class
+        * @return      $resolverInstance                       The prepared controller resolver instance
+        * @throws      EmptyVariableException          Thrown if the default command is not set
+        * @throws      InvalidControllerException      Thrown if the default controller is invalid
+        */
+       public final static function createImageControllerResolver ($controllerName, ManageableApplication $appInstance) {
+               // Create the new instance
+               $resolverInstance = new ImageControllerResolver();
+
+               // Is the variable $controllerName set and the command is valid?
+               if (empty($controllerName)) {
+                       // Then thrown an exception here
+                       throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+               } elseif (!$resolverInstance->isControllerValid($controllerName)) {
+                       // Invalid command found
+                       throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
+               }
+
+               // Set the application instance
+               $resolverInstance->setApplicationInstance($appInstance);
+
+               // Set command name
+               $resolverInstance->setControllerName($controllerName);
+
+               // Return the prepared instance
+               return $resolverInstance;
+       }
+
+       /**
+        * Resolves the default controller of the given command
+        *
+        * @return      $controllerInstance             A controller instance for the default
+        *                                                                      command
+        * @throws      InvalidControllerInstanceException      Thrown if $controllerInstance
+        *                                                                                              is invalid
+        */
+       public function resolveController () {
+               // Init variables
+               $controllerName = "";
+               $controllerInstance = null;
+
+               // Get the command name 
+               $controllerName = $this->getControllerName();
+
+               // Get the command
+               $controllerInstance = $this->loadController($controllerName);
+
+               // And validate it
+               if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) {
+                       // This command has an invalid instance!
+                       throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
+               } // END - if
+
+               // Set last controller
+               $this->lastControllerInstance = $controllerInstance;
+
+               // Return the maybe resolved instance
+               return $controllerInstance;
+       }
+
+       /**
+        * "Loads" a given controller and instances it if not yet cached. If the
+        * controller was not found one of the default controllers will be used
+        * depending on wether news shall be displayed.
+        *
+        * @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!)
+        */
+       private function loadController ($controllerName) {
+                // Debug message
+                //* DEBUG: */ $this->debugBackTrace();
+
+               // Cache default command
+               $defaultController = $this->getConfigInstance()->readConfig('default_image_command');
+
+               // Init controller instance
+               $controllerInstance = null;
+
+               // Default controller
+               $this->setClassName("ImageDefaultController");
+
+               // Generate the class name
+               //* DEBUG: */ echo __METHOD__.": Controller=".$controllerName;
+               if ($controllerName != $defaultController) {
+                       // Create controller class name
+                       $this->setClassName(sprintf("Image%sController",
+                               $this->convertToClassName($controllerName)
+                       ));
+               } else {
+                       // Default controller
+                       $this->setClassName("ImageDefaultController");
+               }
+               //* DEBUG: */ echo ", controller=".$this->getClassName()."<br />\n";
+
+               // Is this class loaded?
+               if (!class_exists($this->getClassName())) {
+                       // Class not found, so try the default one or throw exception
+                       throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
+               } // END - if
+
+               // Initiate the resolver and controller
+               $resolverInstance = ObjectFactory::createObjectByConfiguredName('image_cmd_resolver_class', array($controllerName, $this->getApplicationInstance()));
+               $controllerInstance = ObjectFactory::createObjectByName($this->getClassName(), array($resolverInstance));
+
+               // Remove resolver
+               unset($resolverInstance);
+
+               // Return the result
+               return $controllerInstance;
+       }
+}
+
+// [EOF]
+?>
index ca1aa9204b529a4294a6c243424cda5ebbd90c01..777f8edd926946998c3932c79c8cc11e18848e75 100644 (file)
@@ -70,7 +70,7 @@ class WebControllerResolver extends BaseControllerResolver implements Controller
                        throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
                } elseif (!$resolverInstance->isControllerValid($controllerName)) {
                        // Invalid command found
-                       throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_COMMAND);
+                       throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
                }
 
                // Set the application instance
@@ -122,7 +122,7 @@ class WebControllerResolver extends BaseControllerResolver implements Controller
         *
         * @param       $controllerName                 A controller name we shall look for
         * @return      $controllerInstance             A loaded controller instance
-        * @throws      DefaultControllerException      Thrown if even the default
+        * @throws      InvalidControllerException      Thrown if even the requested
         *                                                                              controller class is missing (bad!)
         */
        private function loadController ($controllerName) {
@@ -130,7 +130,7 @@ class WebControllerResolver extends BaseControllerResolver implements Controller
                 //* DEBUG: */ $this->debugBackTrace();
 
                // Cache default command
-               $defaultController = $this->getConfigInstance()->readConfig('default_command');
+               $defaultController = $this->getConfigInstance()->readConfig('default_web_command');
 
                // Init controller instance
                $controllerInstance = null;
@@ -156,14 +156,8 @@ class WebControllerResolver extends BaseControllerResolver implements Controller
 
                // Is this class loaded?
                if (!class_exists($this->getClassName())) {
-                       // Class not found, so try the default one or throw exception
-                       if ($controllerName != $defaultController) {
-                               // Try the default controller
-                               return $this->loadController($defaultController);
-                       } else {
-                               // Still not found?
-                               throw new DefaultControllerException($this, self::EXCEPTION_DEFAUL_CONTROLLER_GONE);
-                       }
+                       // Throw an exception here
+                       throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
                } // END - if
 
                // Initiate the resolver and controller
index a9e567f0ab16435d3b61d72fc5f5c1eb736fb651..a23d6855caecc5aef0cae2af20008cac093b77c6 100644 (file)
@@ -227,6 +227,9 @@ $cfg->setConfigEntry('news_db_wrapper_class', "NewsDatabaseWrapper");
 // CFG: WEB-CMD-RESOLVER-CLASS
 $cfg->setConfigEntry('web_cmd_resolver_class', "WebCommandResolver");
 
+// CFG: IMAGE-CMD-RESOLVER-CLASS
+$cfg->setConfigEntry('image_cmd_resolver_class', "ImageCommandResolver");
+
 // CFG: MAILER-CLASS
 $cfg->setConfigEntry('mailer_class', "DebugMailer");