/** * Permet de récupérer le contenu du fichier * * @return mixed */ public function getFileContent() { $get = HttpRequest::getInstance()->getData(); if (isset($get['json'])) { $json = true; } else { $json = false; } if ($json) { return $this->file_url; } else { return json_decode($this->file_url, $this->file_assoc, $this->file_depth, $this->file_options); } }
/** * Permet de récupérer le chemin absolu de l'application * * @return string */ public static function getAppPath() : string { if (is_null(self::$_app_path)) { try { $http_request = HttpRequest::getInstance(); $docRoot = $http_request->getDocumentRoot(); $phpSelf = $http_request->getPhpSelf(); } catch (HttpException $e) { echo $e->displayCompleteError(); exit(0); } finally { if (isset($docRoot) && isset($phpSelf)) { $phpSelf = trim(dirname(dirname($phpSelf)), '/'); self::$_app_path = $docRoot . $phpSelf; } } } return self::$_app_path; }
/** * Permet de vérifier si une Route est renseigner et appelle celle-ci * * @return mixed * @throws RouterException */ public function run() { try { $request_method = HttpRequest::getInstance()->getRequestMethod(); } catch (HttpException $e) { echo $e->displayCompleteError(); exit(0); } if (!isset($this->array_routes[$request_method])) { throw new RouterException('Request method doesn\'t exist'); } foreach ($this->array_routes[$request_method] as $route) { if ($route->matchRegex($this->url)) { try { return $route->callContent(); } catch (RouteException $e) { echo $e->displayCompleteError(); exit(0); } } } throw new RouterException('No routes matches'); }