00001 <?php 00024 class BaseControllerResolver extends BaseResolver { 00028 private $controllerPrefix = ""; 00029 00033 private $controllerName = ""; 00034 00041 protected function __construct ($className) { 00042 // Call parent constructor 00043 parent::__construct($className); 00044 } 00045 00052 protected final function setControllerPrefix ($controllerPrefix) { 00053 $this->controllerPrefix = $controllerPrefix; 00054 } 00055 00062 protected final function setControllerName ($controllerName) { 00063 $this->controllerName = $controllerName; 00064 } 00065 00071 public final function getControllerName () { 00072 return $this->controllerName; 00073 } 00074 00083 public function isControllerValid ($controllerName) { 00084 // By default nothing shall be valid 00085 $isValid = false; 00086 00087 // Is a controller set? 00088 if (empty($controllerName)) { 00089 // Then thrown an exception here 00090 throw new EmptyVariableException(array($this, 'controllerName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); 00091 } // END - if 00092 00093 // Now, let us create the full name of the controller class 00094 $this->setClassName(sprintf("%s%sController", 00095 $this->controllerPrefix, 00096 $this->convertToClassName($controllerName) 00097 )); 00098 00099 // Try it hard to get an controller 00100 while ($isValid === false) { 00101 // Is this class already loaded? 00102 if (class_exists($this->getClassName())) { 00103 // This class does exist. :-) 00104 $isValid = true; 00105 } elseif (($this->getClassName() != $this->controllerPrefix.'DefaultController') && ($this->getClassName() != $this->controllerPrefix.'DefaultNewsController')) { 00106 // Do we have news? 00107 if ($this->getConfigInstance()->readConfig('page_with_news') == $this->getApplicationInstance()->getRequestInstance()->getRequestElement('page')) { 00108 // Yes, display news in home then set default controller with news 00109 $this->setClassName($this->controllerPrefix . 'DefaultNewsController'); 00110 } else { 00111 // No news at home page or non-news page 00112 $this->setClassName($this->controllerPrefix . 'DefaultController'); 00113 } 00114 } else { 00115 // All is tried, give it up here 00116 throw new DefaultControllerException($this, self::EXCEPTION_DEFAULT_CONTROLLER_GONE); 00117 } 00118 } // END - while 00119 00120 // Return the result 00121 return $isValid; 00122 } 00123 } 00124 00125 // [EOF] 00126 ?>
1.5.6