/**
  * Finds the exaclty correspondency between the requested routes and the ones defined.<br>
  * If the route exists, it will be execute, otherwise an exception will be throw.
  *
  * @throws MControllerNotExistsException
  * @throws MInvalidControllerException
  * @throws MUndefinedRouteException
  */
 public function run()
 {
     $requestType = strtolower($_SERVER['REQUEST_METHOD']);
     /* @var $requestedRoute MRoute */
     $requestedRoute = $this->routeList->getValue($this->getRequestedRole());
     if ($requestedRoute === null) {
         throw new MUndefinedRouteException($this->getRequestedRole());
     }
     if ($requestedRoute->getType() != MRouteType::CONTROLLER && $requestedRoute->getType() != MRouteType::ALL && $requestedRoute->getType() !== $requestType) {
         throw new MUndefinedRouteException($this->getRequestedRole());
     }
     $className = $requestedRoute->getClass();
     $methodName = $requestedRoute->getMethod();
     if (!class_exists($className)) {
         throw new MControllerNotExistsException($className);
     }
     // If the class is not a {@link MAbstractController} will be run the method defined in the root.
     if ($requestedRoute->getType() !== MRouteType::CONTROLLER) {
         $controller = new $className();
         if ($controller instanceof MAbstractController) {
             $controller->{$methodName}();
         } else {
             throw new MInvalidControllerException($className);
         }
     }
 }
Example #2
0
 /**
  * Returns the value for a specific <i>$key</i>.<br />
  * If the <i>$key</i> is not set a <i>$defaultValue</i> will be returned.
  * 
  * @param string $key
  * @param mixed $defaultValue
  * @return mixed
  */
 public function getValue($key, $defaultValue = null)
 {
     return parent::getValue($key, $defaultValue);
 }
Example #3
0
 /**
  * @param string $id
  * @return MAbstractController
  */
 protected function getControl($id)
 {
     MDataType::mustBeString($id);
     return $this->controls->getValue($id);
 }