diff --git a/config/function.php b/config/function.php index 8d42063..3580c8c 100644 --- a/config/function.php +++ b/config/function.php @@ -119,4 +119,13 @@ function tra(string $message, $value = null): string $i18n = new i18n(Session::get('lang')); $translate_value = !is_array($value) ? [$value] : $value; return $i18n->translate($message, $translate_value); +} + +/** + * get a formatted application route path + * @param string $path + * @return string + */ +function route_path(string $path): string{ + return WEB_ROOT . ltrim($path,'/'); } \ No newline at end of file diff --git a/config/globals.php b/config/globals.php index 39fd723..1654881 100644 --- a/config/globals.php +++ b/config/globals.php @@ -14,6 +14,5 @@ 'lang' => 'fr', 'vendor' => true, 'autoload' => ['src', 'controller', 'middleware', 'models', 'helpers'], - 'helper' => WEB_ROOT, - 'preferences' => WEB_ROOT . 'helper' + 'helpers' => WEB_ROOT, ]; \ No newline at end of file diff --git a/src/Core/MetaData.php b/src/Core/MetaData.php index 7b0d8cd..09a0afd 100644 --- a/src/Core/MetaData.php +++ b/src/Core/MetaData.php @@ -267,7 +267,7 @@ protected function getLink(bool $twitter = false): string /** * @return string|null */ - protected function getType(bool $twitter = fals): string + protected function getType(bool $twitter = false): string { $type = $twitter ? "_type\" />" : ""; return $this->_type ? $type : ''; diff --git a/src/Core/View.php b/src/Core/View.php index f3d38e4..b0f6200 100644 --- a/src/Core/View.php +++ b/src/Core/View.php @@ -103,7 +103,7 @@ public function setFolder(string $folder_name) * * @param string $view */ - function display(string $view) + public function display(string $view) { $view_file = $this->buildFilePath($view); $render = $this->renderView($view_file); @@ -154,8 +154,7 @@ protected function renderView(string $view) */ private function renderNotDefined(string $file_name) { - Response::setStatusCode(404); - print_r(['exception' => "$file_name file path is not correct."]); + Response::send(['exception' => "$file_name file path is not correct."],404); } /** @@ -208,12 +207,12 @@ private function buildAssetHead($html) $xpath = new DOMXPath($dom); $head = $xpath->query('//head/title'); $template = $dom->createDocumentFragment(); - // add style link to the head tag of the page + // add a style link to the head tag of the page foreach (self::$stylelink as $k => $v) { $template->appendXML(''); $head[0]->parentNode->insertbefore($template, $head[0]->nextSibling); } - // add script link to the head of the page + // add a script link to the head of the page foreach (self::$jslink as $k => $v) { $link = $v['link']; $src = ''; @@ -224,7 +223,9 @@ private function buildAssetHead($html) // add metadata to the head of the page if (self::$metadata) { $template->appendXML(self::$metadata); - $head[0]->parentNode->insertbefore($template, $head[0]->nextSibling); + if ($head[0]) { + $head[0]->parentNode->insertbefore($template, $head[0]->nextSibling); + } } print(html_entity_decode($dom->saveHTML())); } catch (Exception $ex) { diff --git a/views/404.php b/views/404.php index 32e037e..f512e25 100644 --- a/views/404.php +++ b/views/404.php @@ -16,7 +16,7 @@