|
|
|
|
@@ -61,9 +61,7 @@ class App extends Main {
|
|
|
|
|
$log = "Method ".$appHandler->className."/".$appHandler->methodName;
|
|
|
|
|
}
|
|
|
|
|
$this->syslogger()->log("handlers", "OK - ".$log);
|
|
|
|
|
/**
|
|
|
|
|
* 1. Если на этапе итерации уже получен ответ ResponseInterface - досрочно отдаем результат в эмиттер
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if($response instanceof ResponseInterface) {
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
@@ -71,16 +69,7 @@ class App extends Main {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 2. Если итерации закончились и задан обьект Content им создаем результат для эмиттера
|
|
|
|
|
*/
|
|
|
|
|
if($this->template() && !empty($this->template()->getResponse())){
|
|
|
|
|
$body = $this->globals()->response()->getBody();
|
|
|
|
|
$body->write($this->template()->getResponse());
|
|
|
|
|
$body->rewind();
|
|
|
|
|
return $this->globals()->response()->withBody($body);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 3. Отдаем пустой результат если не определен шаблонизатор
|
|
|
|
|
* Отдаем пустой результат
|
|
|
|
|
*/
|
|
|
|
|
return $this->defaultPage(404);
|
|
|
|
|
}
|
|
|
|
|
@@ -93,7 +82,7 @@ class App extends Main {
|
|
|
|
|
$this->syslogger()->warning("Exception: ".$exception->getMessage()." : ".$exception->getFile()." : ".$exception->getLine());
|
|
|
|
|
}
|
|
|
|
|
catch (AppError $appError){
|
|
|
|
|
if($this->logger()) $this->logger()->warning($appError->getMessage()." on ".$appError->getFile().":".$appError->getLine());
|
|
|
|
|
if($this->logger()) $this->logger()->error($appError->getMessage()." on ".$appError->getFile().":".$appError->getLine());
|
|
|
|
|
$this->syslogger()->error("Error: ".$appError->getMessage()." : ".$appError->getFile()." : ".$appError->getLine());
|
|
|
|
|
}
|
|
|
|
|
catch (\Error $error) {
|
|
|
|
|
@@ -101,7 +90,7 @@ class App extends Main {
|
|
|
|
|
$this->syslogger()->error("Error: ".$error->getMessage()." : ".$error->getFile()." : ".$error->getLine());
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 4. Отдаем ошибку без шаблона
|
|
|
|
|
* Отдаем после ошибки
|
|
|
|
|
*/
|
|
|
|
|
return $this->defaultPage(501);
|
|
|
|
|
}
|
|
|
|
|
@@ -112,10 +101,7 @@ class App extends Main {
|
|
|
|
|
*/
|
|
|
|
|
private function defaultPage(int $code) : ResponseInterface{
|
|
|
|
|
if(is_file($this->baseDir.'/'.getenv("PAGE".$code))){
|
|
|
|
|
$body = $this->globals()->response()->getBody();
|
|
|
|
|
$body->write(file_get_contents($this->baseDir.'/'.getenv("PAGE".$code)));
|
|
|
|
|
$body->rewind();
|
|
|
|
|
return $this->globals()->response()->withBody($body)->withStatus($code);
|
|
|
|
|
$this->globals()->response()->getBody()->write(file_get_contents($this->baseDir.'/'.getenv("PAGE".$code)));
|
|
|
|
|
}
|
|
|
|
|
return $this->globals()->response()->withStatus($code);
|
|
|
|
|
}
|
|
|
|
|
@@ -180,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){
|
|
|
|
|
|