class_WebGovernmentFailedCommandResolver.php

Go to the documentation of this file.
00001 <?php
00024 class WebGovernmentFailedCommandResolver 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 "Web"
00040                 $this->setCommandPrefix("Web");
00041         }
00042 
00052         public final static function createWebGovernmentFailedCommandResolver ($commandName, ManageableApplication $appInstance) {
00053                 // Create the new instance
00054                 $resolverInstance = new WebGovernmentFailedCommandResolver();
00055 
00056                 // Get request instance
00057                 $requestInstance = $appInstance->getRequestInstance();
00058 
00059                 // Is the variable $commandName set and the command is valid?
00060                 if (empty($commandName)) {
00061                         // Then thrown an exception here
00062                         throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
00063                 } elseif (!$resolverInstance->resolveCommandByRequest($requestInstance) instanceof Commandable) {
00064                         // Invalid command found (missing interface?)
00065                         throw new InvalidInterfaceException(array($userInstance, 'ManageableMember'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING);
00066                 }
00067 
00068                 // Set the application instance
00069                 $resolverInstance->setApplicationInstance($appInstance);
00070 
00071                 // Return the prepared instance
00072                 return $resolverInstance;
00073         }
00074 
00086         public function resolveCommandByRequest (Requestable $requestInstance) {
00087                 // Init instance
00088                 $commandInstance = null;
00089 
00090                 // This goes fine so let's resolv the command
00091                 $commandName = $requestInstance->getRequestElement('page');
00092 
00093                 // Is there a "failed" request?
00094                 if ($requestInstance->isRequestElementSet('failed')) {
00095                         // Then include with within the command name
00096                         $commandName = sprintf("%s_%s", $commandName, $requestInstance->getRequestElement('failed'));
00097                 } // END - if
00098 
00099                 // Is the command empty? Then fall back to default command
00100                 if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_web_command');
00101 
00102                 // Check if command is valid
00103                 if ($this->isCommandValid($commandName) === false) {
00104                         // This command is invalid!
00105                         throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
00106                 } // END - if
00107 
00108                 // Get the command
00109                 $commandInstance = $this->loadCommand($commandName);
00110 
00111                 // And validate it
00112                 if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) {
00113                         // This command has an invalid instance!
00114                         throw new InvalidCommandInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
00115                 } // END - if
00116 
00117                 // Set last command
00118                 $this->lastCommandInstance = $commandInstance;
00119 
00120                 // Return the resolved command instance
00121                 return $commandInstance;
00122         }
00123 
00131         public function resolveCommand ($commandName) {
00132                 // Initiate the instance variable
00133                 $commandInstance = null;
00134 
00135                 // Is the command empty? Then fall back to default command
00136                 if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_web_command');
00137 
00138                 // Check if command is valid
00139                 if ($this->isCommandValid($commandName) === false) {
00140                         // This command is invalid!
00141                         throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
00142                 }
00143 
00144                 // Get the command
00145                 $commandInstance = $this->loadCommand($commandName);
00146 
00147                 // Return the instance
00148                 return $commandInstance;
00149         }
00150 
00159         private function loadCommand ($commandName) {
00160                 // Cache default command
00161                 $defaultCommand = $this->getConfigInstance()->readConfig('default_web_command');
00162 
00163                 // Init command instance
00164                 $commandInstance = null;
00165 
00166                 // Create command class name
00167                 $this->setClassName(sprintf("Web%sCommand",
00168                         $this->convertToClassName($commandName)
00169                 ));
00170 
00171                 // Is this class loaded?
00172                 if (!class_exists($this->getClassName())) {
00173                         // Class not found, so throw an exception
00174                         throw new InvalidCommandException(array($this, $defaultCommand), self::EXCEPTION_INVALID_COMMAND);
00175                 } // END - if
00176 
00177                 // Initiate the command
00178                 $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
00179 
00180                 // Return the result
00181                 return $commandInstance;
00182         }
00183 }
00184 
00185 // [EOF]
00186 ?>

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