]> git.mxchange.org Git - core.git/commitdiff
Moved methods to reduce code duplicates.
authorRoland Haeder <roland@mxchange.org>
Tue, 24 Mar 2015 19:53:09 +0000 (20:53 +0100)
committerRoland Haeder <roland@mxchange.org>
Tue, 24 Mar 2015 19:53:09 +0000 (20:53 +0100)
Signed-off-by: Roland Häder <roland@mxchange.org>
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_
inc/classes/main/resolver/command/web/class_WebCommandResolver.php

index 4d027b3751fb3905363a625d405a1faa169ffc4d..0994bf168f5385f0899ec765edbcdb447b50945e 100644 (file)
@@ -57,6 +57,112 @@ class BaseCommandResolver extends BaseResolver {
                return $this->commandName;
        }
 
+       /**
+        * "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!)
+        */
+       protected function loadCommand ($commandName) {
+               // Init command instance
+               $commandInstance = NULL;
+
+               // Create class name
+               $className = $this->getCapitalizedClassPrefix() . $this->convertToClassName($commandName) . 'Command';
+
+               // Create command class name
+               $this->setClassName($className);
+
+               // Is this class loaded?
+               if (!class_exists($this->getClassName())) {
+                       // Class not found, so throw an exception
+                       throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
+               } // END - if
+
+               // Initiate the command
+               $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
+
+               // Return the result
+               return $commandInstance;
+       }
+
+       /**
+        * 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 resolve the command
+               $commandName = $requestInstance->getRequestElement('command');
+
+               // Is the command empty? Then fall back to default command
+               if (empty($commandName)) {
+                       $commandName = $this->getConfigInstance()->getConfigEntry('default_html_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);
+
+               // 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->setResolvedInstance($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()->getConfigEntry('default_html_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);
+
+               // Return the instance
+               return $commandInstance;
+       }
+
        /**
         * Checks whether the given command is valid
         *
index 87c3c8c639c98c11c1ca30d3db4755eb7b3df066..2b1582c8bb0b3c0b05ab7bfbcbedb1172af40d7d 100644 (file)
@@ -63,112 +63,6 @@ class ConsoleCommandResolver extends BaseCommandResolver implements CommandResol
                // 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 resolve the command
-               $commandName = $requestInstance->getRequestElement('command');
-
-               // Is the command empty? Then fall back to default 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);
-
-               // 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->setResolvedInstance($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()->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);
-
-               // 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) {
-               // Init command instance
-               $commandInstance = NULL;
-
-               // Create class name
-               $className = $this->getCapitalizedClassPrefix() . $this->convertToClassName($commandName) . 'Command';
-
-               // Create command class name
-               $this->setClassName($className);
-
-               // Is this class loaded?
-               if (!class_exists($this->getClassName())) {
-                       // Class not found, so throw an exception
-                       throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
-               } // END - if
-
-               // Initiate the command
-               $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
-
-               // Return the result
-               return $commandInstance;
-       }
 }
 
 // [EOF]
index b0fc8be66508aee9cb06d0c519b4af4860aa268d..80a84dc910266ec06d986a1259f0331023682524 100644 (file)
@@ -37,7 +37,7 @@ class ImageCommandResolver extends BaseCommandResolver implements CommandResolve
                parent::__construct(__CLASS__);
 
                // Set prefix to "Image"
-               $this->setClassPrefix('Image');
+               $this->setClassPrefix('image');
        }
 
        /**
@@ -68,109 +68,6 @@ class ImageCommandResolver extends BaseCommandResolver implements CommandResolve
                // 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 resolve the command
-               $commandName = $requestInstance->getRequestElement('page');
-
-               // Is the command empty? Then fall back to default 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);
-
-               // 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->setResolvedInstance($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()->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);
-
-               // 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) {
-               // Init command instance
-               $commandInstance = NULL;
-
-               // Create class name
-               $className = $this->getCapitalizedClassPrefix() . $this->convertToClassName($commandName) . 'Command';
-
-               // Is this class loaded?
-               if (!class_exists($this->getClassName())) {
-                       // Class not found, so throw an exception
-                       throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
-               } // END - if
-
-               // Initiate the command
-               $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
-
-               // Return the result
-               return $commandInstance;
-       }
 }
 
 // [EOF]
index d96768ab8700e772025b01df3abbda58f6cf4f7d..17bb301748d7888c167c18907a84af75147377bf 100644 (file)
@@ -68,110 +68,6 @@ class Web???CommandResolver extends BaseCommandResolver implements CommandResolv
                // 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()->getConfigEntry('default_html_command');
-
-               // Check if the 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);
-
-               // 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()->getConfigEntry('default_html_command');
-
-               // Check if the command is valid
-               if ($this->isCommandValid($commandName) === FALSE) {
-                       // 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()->getConfigEntry('default_html_command');
-
-               // Init command instance
-               $commandInstance = null;
-
-               // Create command class name
-               $this->setClassName(sprintf("Web%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 9225c454a2f850d79e5dffa14fb094cc5fc2b4bc..146a2e5f62e27b4ef62cd4af97f6f6f03bed88a0 100644 (file)
@@ -68,106 +68,6 @@ class WebCommandResolver extends BaseCommandResolver implements CommandResolver
                // 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 resolve the command
-               $commandName = $requestInstance->getRequestElement('page');
-
-               // Is the command empty? Then fall back to default command
-               if (empty($commandName)) {
-                       $commandName = $this->getConfigInstance()->getConfigEntry('default_html_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);
-
-               // 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->setResolvedInstance($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()->getConfigEntry('default_html_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);
-
-               // 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) {
-               // Init command instance
-               $commandInstance = NULL;
-
-               // Is this class loaded?
-               if (!class_exists($this->getClassName())) {
-                       // Class not found, so throw an exception
-                       throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
-               } // END - if
-
-               // Initiate the command
-               $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
-
-               // Return the result
-               return $commandInstance;
-       }
 }
 
 // [EOF]