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
00037 parent::__construct(__CLASS__);
00038
00039
00040 $this->setCommandPrefix("Web");
00041 }
00042
00052 public final static function createWebGovernmentFailedCommandResolver ($commandName, ManageableApplication $appInstance) {
00053
00054 $resolverInstance = new WebGovernmentFailedCommandResolver();
00055
00056
00057 $requestInstance = $appInstance->getRequestInstance();
00058
00059
00060 if (empty($commandName)) {
00061
00062 throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
00063 } elseif (!$resolverInstance->resolveCommandByRequest($requestInstance) instanceof Commandable) {
00064
00065 throw new InvalidInterfaceException(array($userInstance, 'ManageableMember'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING);
00066 }
00067
00068
00069 $resolverInstance->setApplicationInstance($appInstance);
00070
00071
00072 return $resolverInstance;
00073 }
00074
00086 public function resolveCommandByRequest (Requestable $requestInstance) {
00087
00088 $commandInstance = null;
00089
00090
00091 $commandName = $requestInstance->getRequestElement('page');
00092
00093
00094 if ($requestInstance->isRequestElementSet('failed')) {
00095
00096 $commandName = sprintf("%s_%s", $commandName, $requestInstance->getRequestElement('failed'));
00097 }
00098
00099
00100 if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_web_command');
00101
00102
00103 if ($this->isCommandValid($commandName) === false) {
00104
00105 throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
00106 }
00107
00108
00109 $commandInstance = $this->loadCommand($commandName);
00110
00111
00112 if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) {
00113
00114 throw new InvalidCommandInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
00115 }
00116
00117
00118 $this->lastCommandInstance = $commandInstance;
00119
00120
00121 return $commandInstance;
00122 }
00123
00131 public function resolveCommand ($commandName) {
00132
00133 $commandInstance = null;
00134
00135
00136 if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_web_command');
00137
00138
00139 if ($this->isCommandValid($commandName) === false) {
00140
00141 throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
00142 }
00143
00144
00145 $commandInstance = $this->loadCommand($commandName);
00146
00147
00148 return $commandInstance;
00149 }
00150
00159 private function loadCommand ($commandName) {
00160
00161 $defaultCommand = $this->getConfigInstance()->readConfig('default_web_command');
00162
00163
00164 $commandInstance = null;
00165
00166
00167 $this->setClassName(sprintf("Web%sCommand",
00168 $this->convertToClassName($commandName)
00169 ));
00170
00171
00172 if (!class_exists($this->getClassName())) {
00173
00174 throw new InvalidCommandException(array($this, $defaultCommand), self::EXCEPTION_INVALID_COMMAND);
00175 }
00176
00177
00178 $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
00179
00180
00181 return $commandInstance;
00182 }
00183 }
00184
00185
00186 ?>