20250302#1

This commit is contained in:
User
2025-03-02 19:13:32 +03:00
parent 9fb52d116d
commit 97f6629907
2 changed files with 196 additions and 15 deletions

View File

@@ -34,7 +34,8 @@ class App extends Main {
*/
public function handler(ServerRequestInterface $request, ResponseInterface $response) : ResponseInterface {
try{
$this->init($request, $response);
$this->setGlobals($request, $response);
$this->init();
$this->syslogger()->dump("Request", $request);
$this->syslogger()->dump("Router", $this->router);
$this->syslogger()->dump("routes", $this->appRoutes);
@@ -42,7 +43,7 @@ class App extends Main {
foreach ($this->appRoutes as $appRouteKey => $appHandler){
if(!$appHandler instanceof MatchObject) continue;
$response = null;
$handlerResponse = null;
if(!empty($appHandler->className)){
if(!class_exists($appHandler->className)) {
@@ -57,15 +58,15 @@ class App extends Main {
$this->syslogger()->log("handlers", "Err - Method ".$appHandler->className."/".$appHandler->methodName." is not exists");
continue;
}
$response = (!empty($appHandler->params)) ? $controllers[$appRouteKey]->{$appHandler->methodName}(...$appHandler->params) : $controllers[$appRouteKey]->{$appHandler->methodName}();
$handlerResponse = (!empty($appHandler->params)) ? $controllers[$appRouteKey]->{$appHandler->methodName}(...$appHandler->params) : $controllers[$appRouteKey]->{$appHandler->methodName}();
$log = "Method ".$appHandler->className."/".$appHandler->methodName;
}
$this->syslogger()->log("handlers", "OK - ".$log);
if($response instanceof ResponseInterface) {
return $response;
if($handlerResponse instanceof ResponseInterface) {
return $handlerResponse;
}
elseif($response === false) break;
elseif($handlerResponse === false) break;
}
}
/**
@@ -107,15 +108,10 @@ class App extends Main {
}
/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return void
* @throws AppException
*/
private function init(ServerRequestInterface $request, ResponseInterface $response) : void {
$this->setGlobals($request, $response);
private function init() : void {
// init factories
if(is_file($this->baseDir."/".getenv("APP_COMPONENTS_FILE"))){
$components = include_once $this->baseDir."/".getenv("APP_COMPONENTS_FILE");
@@ -163,8 +159,7 @@ class App extends Main {
if(!empty($appNode['action'])){
$className = $appNode['action'];
$methodName = $appNode['method'];
$params = (!empty($appNode['params']) && is_string($appNode['params'])) ? explode(",",str_replace(" ", "", $appNode['params'])) : [];
$this->appRoutes[] = new MatchObject($className, $methodName, $params);
$this->appRoutes[] = new MatchObject($className, $methodName);
}
elseif(!empty($appNode['router']) && is_array($appNode['router'])){
if(empty($this->router)) throw AppError::invalidRequiredObject("Application config without router");
@@ -190,4 +185,4 @@ class App extends Main {
}
}
}
}
}