Ejemplo n.º 1
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;
 }