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 77% rename from src/Core/View.php rename to src/Core/Views/View.php index 2573d26..d45798a 100644 --- a/src/Core/View.php +++ b/src/Core/Views/View.php @@ -1,18 +1,25 @@ folder_name = Application::getViewFolder(); - } - - /** - * @param string $js_link - * + * Provide js link to be set up on the page header + * @param string $path file path + * @param bool $external set to true for an external link * @return void */ - public static function setJsToHead(string $js_link, bool $external = false) + public static function setJsToHead(string $path, bool $external = false) { - self::$jslink[] = [ - 'link' => $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; } /** @@ -89,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::addSlaches($folder_name); - } - /** * call this method to display file content * @@ -123,12 +106,14 @@ 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; } /** + * Render content from prided file * @param string $view * * @return false|string|void @@ -216,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); } @@ -241,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 @@ -282,9 +250,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 = '';