5 Commits
1.1 ... 2.0.1

Author SHA1 Message Date
User
2a620798b3 20231009#1 2023-10-09 14:12:18 +03:00
User
7658fc88e6 20230926#3 2023-09-26 21:37:02 +03:00
User
5c79d63d6c 20230926#1 2023-09-26 16:34:19 +03:00
User
d43d4751a7 20230818#2 2023-08-18 01:48:17 +03:00
User
c681f88de4 20230818#1 2023-08-18 01:42:24 +03:00
2 changed files with 8 additions and 26 deletions

View File

@@ -9,13 +9,7 @@ Stable version
```bash ```bash
composer require rmphp/kernel composer require rmphp/kernel
``` ```
```bash
composer require rmphp/kernel:"^1.1"
```
Dev version contains the latest changes
```bash ```bash
composer require rmphp/kernel:"1.1.x-dev" composer require rmphp/kernel:"^2.0"
``` ```

View File

@@ -4,6 +4,7 @@ declare(strict_types = 1);
namespace Rmphp\Kernel; namespace Rmphp\Kernel;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
@@ -48,7 +49,7 @@ class App extends Main {
$this->syslogger()->log("handlers", "Err - Class ".$appHandler->className." is not exists"); $this->syslogger()->log("handlers", "Err - Class ".$appHandler->className." is not exists");
continue; continue;
} }
$controllers[$appRouteKey] = new $appHandler->className; $controllers[$appRouteKey] = ($this->container() instanceof ContainerInterface) ? $this->container()->get($appHandler->className) : new $appHandler->className;
$log = "Class ".$appHandler->className; $log = "Class ".$appHandler->className;
if(!empty($appHandler->methodName)){ if(!empty($appHandler->methodName)){
@@ -73,10 +74,8 @@ class App extends Main {
* 2. Если итерации закончились и задан обьект Content им создаем результат для эмиттера * 2. Если итерации закончились и задан обьект Content им создаем результат для эмиттера
*/ */
if($this->template() && !empty($this->template()->getResponse())){ if($this->template() && !empty($this->template()->getResponse())){
$body = $this->globals()->response()->getBody(); $this->globals()->response()->getBody()->write($this->template()->getResponse());
$body->write($this->template()->getResponse()); return$this->globals()->response();
$body->rewind();
return $this->globals()->response()->withBody($body);
} }
/** /**
* 3. Отдаем пустой результат если не определен шаблонизатор * 3. Отдаем пустой результат если не определен шаблонизатор
@@ -87,7 +86,7 @@ class App extends Main {
if($this->logger()) $this->logger()->warning($appException->getMessage()." on ".$appException->getFile().":".$appException->getLine()); if($this->logger()) $this->logger()->warning($appException->getMessage()." on ".$appException->getFile().":".$appException->getLine());
$this->syslogger()->warning("AppException: ".$appException->getMessage()); $this->syslogger()->warning("AppException: ".$appException->getMessage());
} }
catch (\Exception $exception) { catch (\Exception|ContainerExceptionInterface $exception) {
if($this->logger()) $this->logger()->warning($exception->getMessage()." on ".$exception->getFile().":".$exception->getLine()); if($this->logger()) $this->logger()->warning($exception->getMessage()." on ".$exception->getFile().":".$exception->getLine());
$this->syslogger()->warning("Exception: ".$exception->getMessage()." : ".$exception->getFile()." : ".$exception->getLine()); $this->syslogger()->warning("Exception: ".$exception->getMessage()." : ".$exception->getFile()." : ".$exception->getLine());
} }
@@ -111,10 +110,7 @@ class App extends Main {
*/ */
private function defaultPage(int $code) : ResponseInterface{ private function defaultPage(int $code) : ResponseInterface{
if(is_file($this->baseDir.'/'.getenv("PAGE".$code))){ if(is_file($this->baseDir.'/'.getenv("PAGE".$code))){
$body = $this->globals()->response()->getBody(); $this->globals()->response()->getBody()->write(file_get_contents($this->baseDir.'/'.getenv("PAGE".$code)));
$body->write(file_get_contents($this->baseDir.'/'.getenv("PAGE".$code)));
$body->rewind();
return $this->globals()->response()->withBody($body)->withStatus($code);
} }
return $this->globals()->response()->withStatus($code); return $this->globals()->response()->withStatus($code);
} }
@@ -157,11 +153,6 @@ class App extends Main {
if(is_file($this->baseDir."/".getenv("APP_NODES_FILE"))){ if(is_file($this->baseDir."/".getenv("APP_NODES_FILE"))){
$nodes = include_once $this->baseDir."/".getenv("APP_NODES_FILE"); $nodes = include_once $this->baseDir."/".getenv("APP_NODES_FILE");
} }
for ($appNodeNum = 1; getenv("APP_NODE".$appNodeNum); $appNodeNum++){
$nodesCollection[] = json_decode(getenv("APP_NODE".$appNodeNum), true);
}
if(isset($nodesCollection)) $nodes = $nodesCollection;
if(empty($nodes) || !is_array($nodes)) throw AppException::emptyAppNodes(); if(empty($nodes) || !is_array($nodes)) throw AppException::emptyAppNodes();
$this->getActions($nodes); $this->getActions($nodes);
} }
@@ -172,7 +163,7 @@ class App extends Main {
private function getActions(array $appNodes) : void { private function getActions(array $appNodes) : void {
foreach ($appNodes as $appNode){ foreach ($appNodes as $appNode){
// по умолчанию точка монтирования ровна корню // по умолчанию точка монтирования от корня
$mountKey = (!empty($appNode['key'])) ? $appNode['key'] : '/'; $mountKey = (!empty($appNode['key'])) ? $appNode['key'] : '/';
// если url начинается не с точки монтирования смотрим далее // если url начинается не с точки монтирования смотрим далее
@@ -192,9 +183,6 @@ class App extends Main {
if(pathinfo($this->baseDir."/".$appNode['router'])['extension'] == "php") { if(pathinfo($this->baseDir."/".$appNode['router'])['extension'] == "php") {
$this->router->withRules(include_once $this->baseDir."/".$appNode['router']); $this->router->withRules(include_once $this->baseDir."/".$appNode['router']);
} }
elseif(pathinfo($this->baseDir."/".$appNode['router'])['extension'] == "json") {
$this->router->withRules(json_decode(file_get_contents($this->baseDir."/".$appNode['router']), true));
}
elseif(pathinfo($this->baseDir."/".$appNode['router'])['extension'] == "yaml") { elseif(pathinfo($this->baseDir."/".$appNode['router'])['extension'] == "yaml") {
$this->router->withRules(yaml_parse_file($this->baseDir."/".$appNode['router'])); $this->router->withRules(yaml_parse_file($this->baseDir."/".$appNode['router']));
} }