resolveController() was everywhere the same, still you can overwrite it with
[core.git] / inc / classes / main / resolver / controller / class_BaseControllerResolver.php
index 03560545d3c3178e081de2aa1affe3ff0962d319..b9ae868f6fe732367fb1ceb1239427a3924bd3c2 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseControllerResolver extends BaseResolver {
-       /**
-        * Validated controller name
-        */
-       private $controllerName = '';
-
        /**
         * Protected constructor
         *
@@ -38,25 +33,6 @@ class BaseControllerResolver extends BaseResolver {
                parent::__construct($className);
        }
 
-       /**
-        * Setter for controller name
-        *
-        * @param       $controllerName         Last validated controller name
-        * @return      void
-        */
-       protected final function setControllerName ($controllerName) {
-               $this->controllerName = $controllerName;
-       }
-
-       /**
-        * Getter for controller name
-        *
-        * @return      $controllerName Last validated controller name
-        */
-       public final function getControllerName () {
-               return $this->controllerName;
-       }
-
        /**
         * "Loads" a given controller and instances it if not yet cached. If the
         * controller was not found one of the default controllers will be used
@@ -165,6 +141,38 @@ class BaseControllerResolver extends BaseResolver {
                // Return the result
                return $isValid;
        }
+
+       /**
+        * Resolves the default controller of the given command
+        *
+        * @return      $controllerInstance             A controller instance for the default
+        *                                                                      command
+        * @throws      InvalidControllerInstanceException      Thrown if $controllerInstance
+        *                                                                                              is invalid
+        */
+       public function resolveController () {
+               // Init variables
+               $controllerName = '';
+               $controllerInstance = NULL;
+
+               // Get the command name 
+               $controllerName = $this->getControllerName();
+
+               // Get the command
+               $controllerInstance = $this->loadController($controllerName);
+
+               // And validate it
+               if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) {
+                       // This command has an invalid instance!
+                       throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
+               } // END - if
+
+               // Set last controller
+               $this->setResolvedInstance($controllerInstance);
+
+               // Return the maybe resolved instance
+               return $controllerInstance;
+       }
 }
 
 // [EOF]