class_ImageCommandResolver.php

Go to the documentation of this file.
00001 <?php
00024 class ImageCommandResolver extends BaseCommandResolver implements CommandResolver {
00028         private $lastCommandInstance = null;
00029 
00035         protected function __construct () {
00036                 // Call parent constructor
00037                 parent::__construct(__CLASS__);
00038 
00039                 // Set prefix to "Image"
00040                 $this->setCommandPrefix("Image");
00041         }
00042 
00052         public final static function createImageCommandResolver ($commandName, ManageableApplication $appInstance) {
00053                 // Create the new instance
00054                 $resolverInstance = new ImageCommandResolver();
00055 
00056                 // Is the variable $commandName set and the command is valid?
00057                 if (empty($commandName)) {
00058                         // Then thrown an exception here
00059                         throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
00060                 } elseif ($resolverInstance->isCommandValid($commandName) === false) {
00061                         // Invalid command found
00062                         throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND);
00063                 }
00064 
00065                 // Set the application instance
00066                 $resolverInstance->setApplicationInstance($appInstance);
00067 
00068                 // Return the prepared instance
00069                 return $resolverInstance;
00070         }
00071 
00083         public function resolveCommandByRequest (Requestable $requestInstance) {
00084                 // Init variables
00085                 $commandName = "";
00086                 $commandInstance = null;
00087 
00088                 // This goes fine so let's resolv the command
00089                 $commandName = $requestInstance->getRequestElement('page');
00090 
00091                 // Is the command empty? Then fall back to default command
00092                 if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_image_command');
00093 
00094                 // Check if command is valid
00095                 if ($this->isCommandValid($commandName) === false) {
00096                         // This command is invalid!
00097                         throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
00098                 } // END - if
00099 
00100                 // Get the command
00101                 $commandInstance = $this->loadCommand($commandName);
00102 
00103                 // And validate it
00104                 if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) {
00105                         // This command has an invalid instance!
00106                         throw new InvalidCommandInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
00107                 } // END - if
00108 
00109                 // Set last command
00110                 $this->lastCommandInstance = $commandInstance;
00111 
00112                 // Return the resolved command instance
00113                 return $commandInstance;
00114         }
00115 
00123         public function resolveCommand ($commandName) {
00124                 // Initiate the instance variable
00125                 $commandInstance = null;
00126 
00127                 // Is the command empty? Then fall back to default command
00128                 if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_image_command');
00129 
00130                 // Check if command is valid
00131                 if ($this->isCommandValid($commandName) === false) {
00132                         // This command is invalid!
00133                         throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
00134                 }
00135 
00136                 // Get the command
00137                 $commandInstance = $this->loadCommand($commandName);
00138 
00139                 // Return the instance
00140                 return $commandInstance;
00141         }
00142 
00151         private function loadCommand ($commandName) {
00152                 // Cache default command
00153                 $defaultCommand = $this->getConfigInstance()->readConfig('default_image_command');
00154 
00155                 // Init command instance
00156                 $commandInstance = null;
00157 
00158                 // Create command class name
00159                 $this->setClassName(sprintf("Image%sCommand",
00160                         $this->convertToClassName($commandName)
00161                 ));
00162 
00163                 // Is this class loaded?
00164                 if (!class_exists($this->getClassName())) {
00165                         // Class not found, so throw an exception
00166                         throw new InvalidCommandException(array($this, $defaultCommand), self::EXCEPTION_INVALID_COMMAND);
00167                 } // END - if
00168 
00169                 // Initiate the command
00170                 $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
00171 
00172                 // Return the result
00173                 return $commandInstance;
00174         }
00175 }
00176 
00177 // [EOF]
00178 ?>

Generated on Mon Dec 8 01:06:46 2008 for Ship-Simulator by  doxygen 1.5.6