class_WebControllerResolver.php
Go to the documentation of this file.00001 <?php
00024 class WebControllerResolver extends BaseControllerResolver implements ControllerResolver {
00028 private $lastControllerName = "";
00029
00033 private $lastControllerInstance = null;
00034
00040 protected function __construct () {
00041
00042 parent::__construct(__CLASS__);
00043
00044
00045 $this->setControllerPrefix("Web");
00046 }
00047
00057 public final static function createWebControllerResolver ($controllerName, ManageableApplication $appInstance) {
00058
00059 $resolverInstance = new WebControllerResolver();
00060
00061
00062 if (empty($controllerName)) {
00063
00064 throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
00065 } elseif ($resolverInstance->isControllerValid($controllerName) === false) {
00066
00067 throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
00068 }
00069
00070
00071 $resolverInstance->setApplicationInstance($appInstance);
00072
00073
00074 $resolverInstance->setControllerName($controllerName);
00075
00076
00077 return $resolverInstance;
00078 }
00079
00088 public function resolveController () {
00089
00090 $controllerName = "";
00091 $controllerInstance = null;
00092
00093
00094 $controllerName = $this->getControllerName();
00095
00096
00097 $controllerInstance = $this->loadController($controllerName);
00098
00099
00100 if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) {
00101
00102 throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
00103 }
00104
00105
00106 $this->lastControllerInstance = $controllerInstance;
00107
00108
00109 return $controllerInstance;
00110 }
00111
00122 private function loadController ($controllerName) {
00123
00124 $defaultController = $this->getConfigInstance()->readConfig('default_web_command');
00125
00126
00127 $controllerInstance = null;
00128
00129
00130 $this->setClassName('WebDefaultController');
00131
00132
00133
00134 if ($controllerName != $defaultController) {
00135
00136 $this->setClassName(sprintf("Web%sController",
00137 $this->convertToClassName($controllerName)
00138 ));
00139 } elseif ($this->getConfigInstance()->readConfig('page_with_news') == $this->getApplicationInstance()->getRequestInstance()->getRequestElement('page')) {
00140
00141 $this->setClassName('WebDefaultNewsController');
00142 } else {
00143
00144 $this->setClassName('WebDefaultController');
00145 }
00146
00147
00148
00149 if (!class_exists($this->getClassName())) {
00150
00151 throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
00152 }
00153
00154
00155 $resolverConfigEntry = "";
00156
00157
00158 try {
00159
00160 $resolverConfigEntry = sprintf("web_cmd_%s_resolver_class", strtolower($controllerName));
00161
00162
00163 $resolverClass = $this->getConfigInstance()->readConfig($resolverConfigEntry);
00164 } catch (ConfigEntryNotFoundException $e) {
00165
00166 $resolverConfigEntry = "web_cmd_resolver_class";
00167 }
00168
00169
00170 $resolverInstance = ObjectFactory::createObjectByConfiguredName($resolverConfigEntry, array($controllerName, $this->getApplicationInstance()));
00171 $controllerInstance = ObjectFactory::createObjectByName($this->getClassName(), array($resolverInstance));
00172
00173
00174 unset($resolverInstance);
00175
00176
00177 return $controllerInstance;
00178 }
00179 }
00180
00181
00182 ?>