From cf621dbaeff4edf3737561d1989963a7bacbd420 Mon Sep 17 00:00:00 2001 From: User Date: Fri, 12 Apr 2024 02:43:39 +0300 Subject: [PATCH] 20240412#1 --- src/App.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/App.php b/src/App.php index 9fab9e1..1c44721 100644 --- a/src/App.php +++ b/src/App.php @@ -166,17 +166,22 @@ class App extends Main { $params = (!empty($appNode['params']) && is_string($appNode['params'])) ? explode(",",str_replace(" ", "", $appNode['params'])) : []; $this->appRoutes[] = new MatchObject($className, $methodName, $params); } + elseif(!empty($appNode['router']) && is_array($appNode['router'])){ + if(empty($this->router)) throw AppError::invalidRequiredObject("Application config without router"); + $this->router->setStartPoint($mountKey); + $this->router->withRules($appNode['router']); + + $routes = $this->router->match($this->globals()->request()) ?? []; + foreach ($routes as $route){ + $this->appRoutes[] = $route; + } + } elseif(!empty($appNode['router']) && file_exists($this->baseDir."/".$appNode['router'])){ if(empty($this->router)) throw AppError::invalidRequiredObject("Application config without router"); $this->router->setStartPoint($mountKey); - - if(pathinfo($this->baseDir."/".$appNode['router'])['extension'] == "php") { - $this->router->withRules(include_once $this->baseDir."/".$appNode['router']); - } - elseif(pathinfo($this->baseDir."/".$appNode['router'])['extension'] == "yaml") { - $this->router->withRules(yaml_parse_file($this->baseDir."/".$appNode['router'])); - } + ob_start(); $routes = include_once $this->baseDir."/".$appNode['router']; ob_end_clean(); + if(is_array($routes)) $this->router->withRules($routes); $routes = $this->router->match($this->globals()->request()) ?? []; foreach ($routes as $route){