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
00037 parent::__construct(__CLASS__);
00038
00039
00040 $this->setCommandPrefix("Image");
00041 }
00042
00052 public final static function createImageCommandResolver ($commandName, ManageableApplication $appInstance) {
00053
00054 $resolverInstance = new ImageCommandResolver();
00055
00056
00057 if (empty($commandName)) {
00058
00059 throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
00060 } elseif ($resolverInstance->isCommandValid($commandName) === false) {
00061
00062 throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND);
00063 }
00064
00065
00066 $resolverInstance->setApplicationInstance($appInstance);
00067
00068
00069 return $resolverInstance;
00070 }
00071
00083 public function resolveCommandByRequest (Requestable $requestInstance) {
00084
00085 $commandName = "";
00086 $commandInstance = null;
00087
00088
00089 $commandName = $requestInstance->getRequestElement('page');
00090
00091
00092 if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_image_command');
00093
00094
00095 if ($this->isCommandValid($commandName) === false) {
00096
00097 throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
00098 }
00099
00100
00101 $commandInstance = $this->loadCommand($commandName);
00102
00103
00104 if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) {
00105
00106 throw new InvalidCommandInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
00107 }
00108
00109
00110 $this->lastCommandInstance = $commandInstance;
00111
00112
00113 return $commandInstance;
00114 }
00115
00123 public function resolveCommand ($commandName) {
00124
00125 $commandInstance = null;
00126
00127
00128 if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_image_command');
00129
00130
00131 if ($this->isCommandValid($commandName) === false) {
00132
00133 throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
00134 }
00135
00136
00137 $commandInstance = $this->loadCommand($commandName);
00138
00139
00140 return $commandInstance;
00141 }
00142
00151 private function loadCommand ($commandName) {
00152
00153 $defaultCommand = $this->getConfigInstance()->readConfig('default_image_command');
00154
00155
00156 $commandInstance = null;
00157
00158
00159 $this->setClassName(sprintf("Image%sCommand",
00160 $this->convertToClassName($commandName)
00161 ));
00162
00163
00164 if (!class_exists($this->getClassName())) {
00165
00166 throw new InvalidCommandException(array($this, $defaultCommand), self::EXCEPTION_INVALID_COMMAND);
00167 }
00168
00169
00170 $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
00171
00172
00173 return $commandInstance;
00174 }
00175 }
00176
00177
00178 ?>