Host name fixed (a redirect causes an error), duplicate code rewrriten to be more...
authorRoland Häder <roland@mxchange.org>
Sat, 5 Mar 2011 11:09:11 +0000 (11:09 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 5 Mar 2011 11:09:11 +0000 (11:09 +0000)
12 files changed:
inc/classes/main/console/class_ConsoleTools.php
inc/classes/main/resolver/action/class_BaseActionResolver.php
inc/classes/main/resolver/action/web/class_WebActionResolver.php
inc/classes/main/resolver/class_BaseResolver.php
inc/classes/main/resolver/command/class_BaseCommandResolver.php
inc/classes/main/resolver/command/console/class_ConsoleCommandResolver.php
inc/classes/main/resolver/command/image/class_ImageCommandResolver.php
inc/classes/main/resolver/command/web/class_WebCommandResolver.php
inc/classes/main/resolver/controller/class_BaseControllerResolver.php
inc/classes/main/resolver/controller/console/class_ConsoleControllerResolver.php
inc/classes/main/resolver/controller/image/class_ImageControllerResolver.php
inc/classes/main/resolver/controller/web/class_WebControllerResolver.php

index dca2092..33d4d71 100644 (file)
@@ -151,6 +151,7 @@ class ConsoleTools extends BaseFrameworkSystem {
                $helperInstance = new ConsoleTools();
 
                // First get a socket
+               // @TODO Add some DNS caching here
                $socket = fsockopen('188.138.90.169', 80, $errorNo, $errorStr, 5);
 
                // Check if there was an error else
@@ -161,7 +162,7 @@ class ConsoleTools extends BaseFrameworkSystem {
 
                // Prepare the GET request
                $request  = 'GET /ip.php HTTP/1.0' . self::HTTP_EOL;
-               $request .= 'Host: www.ship-simu.org' . self::HTTP_EOL;
+               $request .= 'Host: ship-simu.org' . self::HTTP_EOL;
                $request .= 'User-Agent: ' . self::HTTP_USER_AGENT . self::HTTP_EOL;
                $request .= 'Connection: close' . self::HTTP_EOL;
                $request .= self::HTTP_EOL;
index 61b6033..601b00e 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseActionResolver extends BaseResolver {
-       /**
-        * Prefix for local, remote or other resolver
-        */
-       private $actionPrefix = '';
-
        /**
         * Validated action name
         */
@@ -43,16 +38,6 @@ class BaseActionResolver extends BaseResolver {
                parent::__construct($className);
        }
 
-       /**
-        * Setter for action prefix
-        *
-        * @param       $actionPrefix   Last validated actionPrefix
-        * @return      void
-        */
-       protected final function setActionPrefix ($actionPrefix) {
-               $this->actionPrefix = $actionPrefix;
-       }
-
        /**
         * Setter for action name
         *
@@ -90,7 +75,7 @@ class BaseActionResolver extends BaseResolver {
                } // END - if
 
                // Create class name
-               $className = $this->actionPrefix . $this->convertToClassName($actionName) . 'Action';
+               $className = $this->getClassPrefix() . $this->convertToClassName($actionName) . 'Action';
 
                // Now, let us create the full name of the action class
                $this->setClassName($className);
@@ -118,7 +103,7 @@ class BaseActionResolver extends BaseResolver {
                $actionInstance = null;
 
                // Create action class name
-               $className = $this->actionPrefix . $this->convertToClassName($this->getActionName()) . 'Action';
+               $className = $this->getClassPrefix() . $this->convertToClassName($this->getActionName()) . 'Action';
 
                // ... and set it
                $this->setClassName($className);
index de659a3..b88d7c4 100644 (file)
@@ -25,7 +25,7 @@ class WebActionResolver extends BaseActionResolver implements ActionResolver {
        /**
         * Last successfull resolved action
         */
-       private $lastActionInstance = '';
+       private $lastActionInstance = null;
 
        /**
         * Protected constructor
@@ -37,7 +37,7 @@ class WebActionResolver extends BaseActionResolver implements ActionResolver {
                parent::__construct(__CLASS__);
 
                // Set prefix to "Web"
-               $this->setActionPrefix("Web");
+               $this->setClassPrefix('Web');
        }
 
        /**
@@ -89,7 +89,9 @@ class WebActionResolver extends BaseActionResolver implements ActionResolver {
                $actionName = $requestInstance->getRequestElement('action');
 
                // Is the action empty? Then fall back to default action
-               if (empty($actionName)) $actionName = $this->getConfigInstance()->getConfigEntry('default_action');
+               if (empty($actionName)) {
+                       $actionName = $this->getConfigInstance()->getConfigEntry('default_action');
+               } // END - if
 
                // Check if action is valid
                if ($this->isActionValid($actionName) === false) {
@@ -107,7 +109,7 @@ class WebActionResolver extends BaseActionResolver implements ActionResolver {
                } // END - if
 
                // Set last action
-               $this->lastActionInstance = $actionInstance;
+               $this->setResolvedInstance($actionInstance);
 
                // Return the resolved action instance
                return $actionInstance;
@@ -127,13 +129,15 @@ class WebActionResolver extends BaseActionResolver implements ActionResolver {
                $actionName = $this->getActionName();
 
                // Is the action empty? Then fall back to default action
-               if (empty($actionName)) $actionName = $this->getConfigInstance()->getConfigEntry('default_action');
+               if (empty($actionName)) {
+                       $actionName = $this->getConfigInstance()->getConfigEntry('default_action');
+               } // END - if
 
                // Check if action is valid
                if ($this->isActionValid($actionName) === false) {
                        // This action is invalid!
                        throw new InvalidActionException(array($this, $actionName), self::EXCEPTION_INVALID_ACTION);
-               }
+               } // END - if
 
                // Get the action
                $actionInstance = $this->loadAction();
index c7cb14a..58cc571 100644 (file)
@@ -27,6 +27,16 @@ class BaseResolver extends BaseFrameworkSystem {
         */
        private $className = '';
 
+       /**
+        * Prefix for class
+        */
+       private $classPrefix = '';
+
+       /**
+        * (Last) resolved instance
+        */
+       private $resolvedInstance = null;
+
        // Exception constants
        const EXCEPTION_INVALID_COMMAND    = 0x1d0;
        const EXCEPTION_INVALID_CONTROLLER = 0x1d1;
@@ -44,6 +54,15 @@ class BaseResolver extends BaseFrameworkSystem {
                parent::__construct($className);
        }
 
+       /**
+        * Getter for class name
+        *
+        * @return      $className      Name of the class
+        */
+       public final function getClassName () {
+               return $this->className;
+       }
+
        /**
         * Setter for class name
         *
@@ -51,16 +70,45 @@ class BaseResolver extends BaseFrameworkSystem {
         * @return      void
         */
        protected final function setClassName ($className) {
-               $this->className = $className;
+               $this->className = (string) $className;
        }
 
        /**
-        * Getter for class name
+        * Getter for class prefix
         *
-        * @return      $className      Name of the class
+        * @return      $classPrefix    Last validated classPrefix
         */
-       public final function getClassName () {
-               return $this->className;
+       protected final function getClassPrefix () {
+               return $this->classPrefix;
+       }
+
+       /**
+        * Setter for class prefix
+        *
+        * @param       $classPrefix    Last validated classPrefix
+        * @return      void
+        */
+       protected final function setClassPrefix ($classPrefix) {
+               $this->classPrefix = (string) $classPrefix;
+       }
+
+       /**
+        * Getter for (last) resolved instance
+        *
+        * @return      $resolvedInstance       Last validated resolvedInstance
+        */
+       protected final function getResolvedInstance () {
+               return $this->resolvedInstance;
+       }
+
+       /**
+        * Setter for (last) resolved instance
+        *
+        * @param       $resolvedInstance       (Last) validated resolved instance
+        * @return      void
+        */
+       protected final function setResolvedInstance (FrameworkInterface $resolvedInstance) {
+               $this->resolvedInstance = $resolvedInstance;
        }
 }
 
index 6bef7f0..02d09cc 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseCommandResolver extends BaseResolver {
-       /**
-        * Prefix for local, remote or other resolver
-        */
-       private $commandPrefix = '';
-
        /**
         * Validated command name
         */
@@ -43,25 +38,6 @@ class BaseCommandResolver extends BaseResolver {
                parent::__construct($className);
        }
 
-       /**
-        * Getter for command prefix
-        *
-        * @return      $commandPrefix  Last validated commandPrefix
-        */
-       protected final function getCommandPrefix () {
-               return $this->commandPrefix;
-       }
-
-       /**
-        * Setter for command prefix
-        *
-        * @param       $commandPrefix  Last validated commandPrefix
-        * @return      void
-        */
-       protected final function setCommandPrefix ($commandPrefix) {
-               $this->commandPrefix = $commandPrefix;
-       }
-
        /**
         * Setter for command name
         *
@@ -99,7 +75,7 @@ class BaseCommandResolver extends BaseResolver {
                } // END - if
 
                // Create the full class name
-               $className = $this->getCommandPrefix() . $this->convertToClassName($commandName) . 'Command';
+               $className = $this->getClassPrefix() . $this->convertToClassName($commandName) . 'Command';
 
                // Now, let us create the full name of the command class
                $this->setClassName($className);
index 6611129..8aefd8c 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class ConsoleCommandResolver extends BaseCommandResolver implements CommandResolver {
-       /**
-        * Last successfull resolved command
-        */
-       private $lastCommandInstance = null;
-
        /**
         * Protected constructor
         *
@@ -37,7 +32,7 @@ class ConsoleCommandResolver extends BaseCommandResolver implements CommandResol
                parent::__construct(__CLASS__);
 
                // Set prefix to "Console"
-               $this->setCommandPrefix('Console');
+               $this->setClassPrefix('Console');
        }
 
        /**
@@ -89,7 +84,9 @@ class ConsoleCommandResolver extends BaseCommandResolver implements CommandResol
                $commandName = $requestInstance->getRequestElement('command');
 
                // Is the command empty? Then fall back to default command
-               if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_console_command');
+               if (empty($commandName)) {
+                       $commandName = $this->getConfigInstance()->getConfigEntry('default_console_command');
+               } // END - if
 
                // Check if command is valid
                if ($this->isCommandValid($commandName) === false) {
@@ -107,7 +104,7 @@ class ConsoleCommandResolver extends BaseCommandResolver implements CommandResol
                } // END - if
 
                // Set last command
-               $this->lastCommandInstance = $commandInstance;
+               $this->setResolvedInstance($commandInstance);
 
                // Return the resolved command instance
                return $commandInstance;
@@ -125,13 +122,15 @@ class ConsoleCommandResolver extends BaseCommandResolver implements CommandResol
                $commandInstance = null;
 
                // Is the command empty? Then fall back to default command
-               if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_console_command');
+               if (empty($commandName)) {
+                       $commandName = $this->getConfigInstance()->getConfigEntry('default_console_command');
+               } // END - if
 
                // Check if command is valid
                if ($this->isCommandValid($commandName) === false) {
                        // This command is invalid!
                        throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
-               }
+               } // END - if
 
                // Get the command
                $commandInstance = $this->loadCommand($commandName);
@@ -153,7 +152,7 @@ class ConsoleCommandResolver extends BaseCommandResolver implements CommandResol
                $commandInstance = null;
 
                // Create class name
-               $className = $this->getCommandPrefix() . $this->convertToClassName($commandName) . 'Command';
+               $className = $this->getClassPrefix() . $this->convertToClassName($commandName) . 'Command';
 
                // Create command class name
                $this->setClassName($className);
index fee6f4f..cc57122 100644 (file)
@@ -37,7 +37,7 @@ class ImageCommandResolver extends BaseCommandResolver implements CommandResolve
                parent::__construct(__CLASS__);
 
                // Set prefix to "Image"
-               $this->setCommandPrefix('Image');
+               $this->setClassPrefix('Image');
        }
 
        /**
@@ -89,7 +89,9 @@ class ImageCommandResolver extends BaseCommandResolver implements CommandResolve
                $commandName = $requestInstance->getRequestElement('page');
 
                // Is the command empty? Then fall back to default command
-               if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_image_command');
+               if (empty($commandName)) {
+                       $commandName = $this->getConfigInstance()->getConfigEntry('default_image_command');
+               } // END - if
 
                // Check if command is valid
                if ($this->isCommandValid($commandName) === false) {
@@ -107,7 +109,7 @@ class ImageCommandResolver extends BaseCommandResolver implements CommandResolve
                } // END - if
 
                // Set last command
-               $this->lastCommandInstance = $commandInstance;
+               $this->setResolvedInstance($commandInstance);
 
                // Return the resolved command instance
                return $commandInstance;
@@ -125,13 +127,15 @@ class ImageCommandResolver extends BaseCommandResolver implements CommandResolve
                $commandInstance = null;
 
                // Is the command empty? Then fall back to default command
-               if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_image_command');
+               if (empty($commandName)) {
+                       $commandName = $this->getConfigInstance()->getConfigEntry('default_image_command');
+               } // END - if
 
                // Check if command is valid
                if ($this->isCommandValid($commandName) === false) {
                        // This command is invalid!
                        throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
-               }
+               } // END - if
 
                // Get the command
                $commandInstance = $this->loadCommand($commandName);
@@ -153,7 +157,7 @@ class ImageCommandResolver extends BaseCommandResolver implements CommandResolve
                $commandInstance = null;
 
                // Create class name
-               $className = $this->getCommandPrefix() . $this->convertToClassName($commandName) . 'Command';
+               $className = $this->getClassPrefix() . $this->convertToClassName($commandName) . 'Command';
 
                // Is this class loaded?
                if (!class_exists($this->getClassName())) {
index fd51fc3..a19ff10 100644 (file)
@@ -37,7 +37,7 @@ class WebCommandResolver extends BaseCommandResolver implements CommandResolver
                parent::__construct(__CLASS__);
 
                // Set prefix to "Web"
-               $this->setCommandPrefix('Web');
+               $this->setClassPrefix('Web');
        }
 
        /**
@@ -89,7 +89,9 @@ 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()->getConfigEntry('default_web_command');
+               if (empty($commandName)) {
+                       $commandName = $this->getConfigInstance()->getConfigEntry('default_web_command');
+               } // END - if
 
                // Check if command is valid
                if ($this->isCommandValid($commandName) === false) {
@@ -107,7 +109,7 @@ class WebCommandResolver extends BaseCommandResolver implements CommandResolver
                } // END - if
 
                // Set last command
-               $this->lastCommandInstance = $commandInstance;
+               $this->setResolvedInstance($commandInstance);
 
                // Return the resolved command instance
                return $commandInstance;
@@ -125,7 +127,9 @@ class WebCommandResolver extends BaseCommandResolver implements CommandResolver
                $commandInstance = null;
 
                // Is the command empty? Then fall back to default command
-               if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_web_command');
+               if (empty($commandName)) {
+                       $commandName = $this->getConfigInstance()->getConfigEntry('default_web_command');
+               } // END - if
 
                // Check if command is valid
                if ($this->isCommandValid($commandName) === false) {
index 0c39b38..3cef50b 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseControllerResolver extends BaseResolver {
-       /**
-        * Prefix for local, remote or other resolver
-        */
-       private $controllerPrefix = '';
-
        /**
         * Validated controller name
         */
@@ -43,26 +38,6 @@ class BaseControllerResolver extends BaseResolver {
                parent::__construct($className);
        }
 
-       /**
-        * Setter for controller prefix
-        *
-        * @param       $controllerPrefix       Last validated controllerPrefix
-        * @return      void
-        */
-       protected final function setControllerPrefix ($controllerPrefix) {
-               $this->controllerPrefix = $controllerPrefix;
-       }
-
-       /**
-        * Getter for controller prefix
-        *
-        * @param       $controllerPrefix       Last validated controllerPrefix
-        * @return      void
-        */
-       protected final function getControllerPrefix () {
-               return $this->controllerPrefix;
-       }
-
        /**
         * Setter for controller name
         *
@@ -94,25 +69,25 @@ class BaseControllerResolver extends BaseResolver {
         */
        protected function loadController ($controllerName) {
                // Cache default command
-               $defaultController = $this->getConfigInstance()->getConfigEntry('default_' . strtolower($this->getControllerPrefix()) . '_command');
+               $defaultController = $this->getConfigInstance()->getConfigEntry('default_' . strtolower($this->getClassPrefix()) . '_command');
 
                // Init controller instance
                $controllerInstance = null;
 
                // Default controller
-               $this->setClassName($this->getControllerPrefix() . 'DefaultNewsController');
+               $this->setClassName($this->getClassPrefix() . 'DefaultNewsController');
 
                // Generate the class name
                //* DEBUG: */ echo __METHOD__.": Controller=".$controllerName;
                if ($controllerName != $defaultController) {
                        // Create controller class name
-                       $className = $this->getControllerPrefix() . '' . $this->convertToClassName($controllerName) . 'Controller';
+                       $className = $this->getClassPrefix() . $this->convertToClassName($controllerName) . 'Controller';
 
                        // ... and set it
                        $this->setClassName($className);
                } else {
                        // No news at main command or non-news command
-                       $this->setClassName($this->getControllerPrefix() . 'DefaultNewsController');
+                       $this->setClassName($this->getClassPrefix() . 'DefaultNewsController');
                }
                //* DEBUG: */ echo ", controller=".$this->getClassName()."<br />\n";
 
@@ -126,7 +101,7 @@ class BaseControllerResolver extends BaseResolver {
                $resolverConfigEntry = '';
 
                // Try to read a config entry for our resolver including controller name... ;-)
-               $resolverConfigEntry = sprintf("%s_cmd_%s_resolver_class", strtolower($this->getControllerPrefix()), strtolower($controllerName));
+               $resolverConfigEntry = sprintf("%s_cmd_%s_resolver_class", strtolower($this->getClassPrefix()), strtolower($controllerName));
 
                // Get the config, this will throw an exception if there is no special command resolver
                $resolverClass = $this->getConfigInstance()->getConfigEntry($resolverConfigEntry);
@@ -167,7 +142,7 @@ class BaseControllerResolver extends BaseResolver {
                } // END - if
 
                // Create class name
-               $className = $this->controllerPrefix . $this->convertToClassName($controllerName) . 'Controller';
+               $className = $this->getClassPrefix() . $this->convertToClassName($controllerName) . 'Controller';
 
                // Now, let us create the full name of the controller class
                $this->setClassName($className);
@@ -178,9 +153,9 @@ class BaseControllerResolver extends BaseResolver {
                        if (class_exists($this->getClassName())) {
                                // This class does exist. :-)
                                $isValid = true;
-                       } elseif ($this->getClassName() != $this->controllerPrefix.'DefaultNewsController') {
+                       } elseif ($this->getClassName() != $this->getClassPrefix() . 'DefaultNewsController') {
                                // Set default controller
-                               $this->setClassName($this->controllerPrefix . 'DefaultNewsController');
+                               $this->setClassName($this->getClassPrefix() . 'DefaultNewsController');
                        } else {
                                // All is tried, give it up here
                                throw new DefaultControllerException($this, self::EXCEPTION_DEFAULT_CONTROLLER_GONE);
index 9df8266..6803513 100644 (file)
@@ -42,7 +42,7 @@ class ConsoleControllerResolver extends BaseControllerResolver implements Contro
                parent::__construct(__CLASS__);
 
                // Set prefix to "Console"
-               $this->setControllerPrefix('Console');
+               $this->setClassPrefix('Console');
        }
 
        /**
@@ -103,7 +103,7 @@ class ConsoleControllerResolver extends BaseControllerResolver implements Contro
                } // END - if
 
                // Set last controller
-               $this->lastControllerInstance = $controllerInstance;
+               $this->setResolvedInstance($controllerInstance);
 
                // Return the maybe resolved instance
                return $controllerInstance;
index 0c3737e..41d66fa 100644 (file)
@@ -42,7 +42,7 @@ class ImageControllerResolver extends BaseControllerResolver implements Controll
                parent::__construct(__CLASS__);
 
                // Set prefix to 'Image'
-               $this->setControllerPrefix('Image');
+               $this->setClassPrefix('Image');
        }
 
        /**
@@ -103,7 +103,7 @@ class ImageControllerResolver extends BaseControllerResolver implements Controll
                } // END - if
 
                // Set last controller
-               $this->lastControllerInstance = $controllerInstance;
+               $this->setResolvedInstance($controllerInstance);
 
                // Return the maybe resolved instance
                return $controllerInstance;
index 157b1b5..8cf46cc 100644 (file)
@@ -42,7 +42,7 @@ class WebControllerResolver extends BaseControllerResolver implements Controller
                parent::__construct(__CLASS__);
 
                // Set prefix to 'Web'
-               $this->setControllerPrefix('Web');
+               $this->setClassPrefix('Web');
        }
 
        /**
@@ -103,7 +103,7 @@ class WebControllerResolver extends BaseControllerResolver implements Controller
                } // END - if
 
                // Set last controller
-               $this->lastControllerInstance = $controllerInstance;
+               $this->setResolvedInstance($controllerInstance);
 
                // Return the maybe resolved instance
                return $controllerInstance;