private function initController()
 {
     $controllerName = $this->controllerName;
     if (!Helpers::startsWith($controllerName, AppConfig::CONTROLLERS_NAMESPACE)) {
         $controllerName = AppConfig::CONTROLLERS_NAMESPACE . ucfirst($this->controllerName) . AppConfig::CONTROLLERS_SUFFIX;
     }
     class_exists($controllerName, false);
     $annotationsParser = new AnnotationsParser($controllerName, $this->actionName);
     $annotationsParser->checkAnnotations();
     $this->controller = new $controllerName(HttpContext::getInstance());
 }
Ejemplo n.º 2
0
 private function searchCustomRoutes(array $requestParams) : bool
 {
     foreach ($this->customRoutes as $key => $val) {
         if (!in_array($_SERVER['REQUEST_METHOD'], $val["methods"])) {
             continue;
         }
         $found = true;
         $tempParams = array();
         if (Helpers::startsWith($key, $this->controller . "/" . $this->action)) {
             if (count($requestParams) === count($val["parameters"])) {
                 for ($i = 0; $i < count($val["parameters"]); $i++) {
                     if ($val["parameters"][$i] === "{int}" && Helpers::isInteger($requestParams[$i])) {
                         $tempParams[] = intval($requestParams[$i]);
                     } else {
                         if ($val["parameters"][$i] === "{str}") {
                             $tempParams[] = $requestParams[$i];
                         } else {
                             if ($val["parameters"][$i] !== $requestParams[$i]) {
                                 $found = false;
                                 break;
                             }
                         }
                     }
                 }
                 if ($found) {
                     $this->controller = lcfirst(substr($val["controller"], 0, strlen($val["controller"]) - strlen(AppConfig::CONTROLLERS_SUFFIX)));
                     $this->action = $val["action"];
                     $this->params = $tempParams;
                     return true;
                 }
             }
         }
     }
     return false;
 }