From 31868ccc825e85c4e734122b864f6b4051b58004 Mon Sep 17 00:00:00 2001 From: bim-g Date: Mon, 2 Sep 2024 03:07:13 +0200 Subject: [PATCH 1/5] [UPD] rename resetconfig method to flush --- src/Core/View.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Core/View.php b/src/Core/View.php index 2573d26..2d2d97f 100644 --- a/src/Core/View.php +++ b/src/Core/View.php @@ -282,9 +282,10 @@ public function setLayoutContent(string $layout_name) } /** + * Reset view to default configuration * @return void */ - public function resetConfig(){ + public function flush(){ $this->reset = true; $this->layout = ''; $this->folder_name = ''; From 040d8ed6c2db9989efe4259772db50e169045b9e Mon Sep 17 00:00:00 2001 From: bim-g Date: Mon, 2 Sep 2024 03:15:24 +0200 Subject: [PATCH 2/5] [UPD] rename addslaches to addSlashes --- src/Core/Escape.php | 9 ++------- src/Core/Http/Redirect.php | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Core/Escape.php b/src/Core/Escape.php index 0c2a1e3..edb139e 100644 --- a/src/Core/Escape.php +++ b/src/Core/Escape.php @@ -48,14 +48,9 @@ public static function randomString(int $length = 8): string * @param string $link * @return string */ - public static function addSlaches(string $link): string + public static function addSlashes(string $link): string { - $sub_string = substr($link, 0, 1); - $new_link = substr($link, 1); - if ($sub_string == '/') { - $link = substr(self::addSlaches($new_link), 1); - } - return $link == '' ? $link : '/' . $link; + return "/" . trim($link,"/"); } /** diff --git a/src/Core/Http/Redirect.php b/src/Core/Http/Redirect.php index da66065..6c92bda 100644 --- a/src/Core/Http/Redirect.php +++ b/src/Core/Http/Redirect.php @@ -30,7 +30,7 @@ static function to($location = null) exit(); } else { $webroot = substr(WEB_ROOT, 0, -1); - $link = Escape::addSlaches($location); + $link = Escape::addSlashes($location); $location = $link == '' ? WEB_ROOT : $webroot . $link; header('Location:' . $location); exit(); From ac5cb4b8b99685f94c5c54ec3a2cb3da70d85a8f Mon Sep 17 00:00:00 2001 From: bim-g Date: Mon, 2 Sep 2024 03:16:07 +0200 Subject: [PATCH 3/5] [UPD] remove contructor params that are not used often --- src/Core/View.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/Core/View.php b/src/Core/View.php index 2d2d97f..6c4aae5 100644 --- a/src/Core/View.php +++ b/src/Core/View.php @@ -47,14 +47,6 @@ class View */ private string $layout_content = ''; - /** - * - */ - public function __construct() - { - $this->folder_name = Application::getViewFolder(); - } - /** * @param string $js_link * @@ -95,7 +87,7 @@ public static function setMetaData(MetaData $metadata) */ public function setFolder(string $folder_name) { - $this->folder_name = Escape::addSlaches($folder_name); + $this->folder_name = Escape::addSlashes($folder_name); } /** @@ -123,8 +115,9 @@ public function display(string $view) */ private function buildFilePath(string $file_name): ?string { + $folder = strlen(trim($this->folder_name)) > 0 ? $this->folder_name : Application::getViewFolder();; $view_file = Escape::checkFileExtension($file_name); - $file_source = $this->folder_name . Escape::addSlaches($view_file); + $file_source = $folder . Escape::addSlashes($view_file); return Application::$ROOT_DIR . '/views' . $file_source; } From db246208e409d869063450259b20a4ff810a3e00 Mon Sep 17 00:00:00 2001 From: bim-g Date: Mon, 2 Sep 2024 04:10:41 +0200 Subject: [PATCH 4/5] [UPD] Repalce CoreException by WepesiException --- src/Core/CoreException/RoutingException.php | 11 ----------- src/Core/Exceptions/RoutingException.php | 14 ++++++++++++++ src/Core/Exceptions/WepesiException.php | 11 +++++++++++ src/Core/Routing/Router.php | 2 +- 4 files changed, 26 insertions(+), 12 deletions(-) delete mode 100644 src/Core/CoreException/RoutingException.php create mode 100644 src/Core/Exceptions/RoutingException.php create mode 100644 src/Core/Exceptions/WepesiException.php diff --git a/src/Core/CoreException/RoutingException.php b/src/Core/CoreException/RoutingException.php deleted file mode 100644 index 42587d4..0000000 --- a/src/Core/CoreException/RoutingException.php +++ /dev/null @@ -1,11 +0,0 @@ - Date: Mon, 2 Sep 2024 04:13:25 +0200 Subject: [PATCH 5/5] [UPD] refactor view module --- router/route.php | 2 +- src/Core/Controller.php | 7 +- .../Views/Provider/Contract/ViewsContract.php | 40 +++++++++ .../Views/Provider/ViewBuilderProvider.php | 55 ++++++++++++ src/Core/{ => Views}/View.php | 83 +++++++------------ 5 files changed, 130 insertions(+), 57 deletions(-) create mode 100644 src/Core/Views/Provider/Contract/ViewsContract.php create mode 100644 src/Core/Views/Provider/ViewBuilderProvider.php rename src/Core/{ => Views}/View.php (80%) diff --git a/router/route.php b/router/route.php index 65567fa..396b5c6 100644 --- a/router/route.php +++ b/router/route.php @@ -1,7 +1,7 @@ router(); diff --git a/src/Core/Controller.php b/src/Core/Controller.php index 95c9911..f8c0539 100644 --- a/src/Core/Controller.php +++ b/src/Core/Controller.php @@ -1,10 +1,13 @@ folder_name = Escape::addSlashes($folder_name); + } + + /** + * @inheritDoc + */ + public function display(string $view) + { + // TODO: Implement display() method. + } + + /** + * assign variables data to be displayed on file_page + * + * @param string $variable + * @param $value + */ + public function assign(string $variable, $value) + { + $this->data[$variable] = $value; + } + + /** + * List all data assigned before being displayed + * @return array + */ + public function getAssignData(): array + { + return $this->data; + } +} \ No newline at end of file diff --git a/src/Core/View.php b/src/Core/Views/View.php similarity index 80% rename from src/Core/View.php rename to src/Core/Views/View.php index 6c4aae5..d45798a 100644 --- a/src/Core/View.php +++ b/src/Core/Views/View.php @@ -1,18 +1,25 @@ $js_link, - 'external' => $external - ]; + self::$js_link_path[] = $path; } /** - * @param string $style_link + * Provide css link path to set up stylesheet on the page header + * + * @param string $path * * @return void * add */ - public static function setStyleToHead(string $style_link) + public static function setStyleToHead(string $path) { - self::$stylelink[] = $style_link; + self::$style_link_path[] = $path; } /** @@ -81,15 +81,6 @@ public static function setMetaData(MetaData $metadata) self::$metadata = $metadata->build(); } - /** - * @param string $folder_name - * @return void - */ - public function setFolder(string $folder_name) - { - $this->folder_name = Escape::addSlashes($folder_name); - } - /** * call this method to display file content * @@ -122,6 +113,7 @@ private function buildFilePath(string $file_name): ?string } /** + * Render content from prided file * @param string $view * * @return false|string|void @@ -209,15 +201,14 @@ private function buildAssetHead($html) $head = $xpath->query('//head/title'); $template = $dom->createDocumentFragment(); // add a style link to the head tag of the page - foreach (self::$stylelink as $k => $v) { + foreach (self::$style_link_path as $k => $v) { $template->appendXML(''); $head[0]->parentNode->insertbefore($template, $head[0]->nextSibling); } // add a script link to the head of the page - foreach (self::$jslink as $k => $v) { + foreach (self::$js_link_path as $k => $v) { $link = $v['link']; $src = ''; - if (!$v['external']) $src = Bundles::insertJS($link, false, true); $template->appendXML($src); $head[0]->parentNode->insertbefore($template, $head[0]->nextSibling); } @@ -234,25 +225,9 @@ private function buildAssetHead($html) } } - /** - * assign variables data to be displayed on file_page - * - * @param string $variable - * @param $value - */ - public function assign(string $variable, $value) - { - $this->data[$variable] = $value; - } - /** - * List all data assigned before being displayed - * @return array - */ - public function getAssignData(): array - { - return $this->data; - } + + /** * you should provide the extension of your file, * in another case the file will be missing