7 Commits
1.0 ... 2.0

Author SHA1 Message Date
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
User
d5a9d0fc10 20230626#3 2023-06-26 20:29:49 +03:00
User
407529f092 20230626#2 2023-06-26 20:13:30 +03:00
User
1f902c6b70 20230626#1 2023-06-26 19:58:04 +03:00
2 changed files with 10 additions and 21 deletions

View File

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

View File

@@ -4,6 +4,7 @@ declare(strict_types = 1);
namespace Rmphp\Kernel;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
@@ -34,6 +35,8 @@ class App extends Main {
public function handler(ServerRequestInterface $request, ResponseInterface $response) : ResponseInterface {
try{
$this->init($request, $response);
$this->syslogger()->dump("Request", $request);
$this->syslogger()->dump("Router", $this->router);
$this->syslogger()->dump("routes", $this->appRoutes);
foreach ($this->appRoutes as $appRouteKey => $appHandler){
@@ -46,8 +49,8 @@ class App extends Main {
$this->syslogger()->log("handlers", "Err - Class ".$appHandler->className." is not exists");
continue;
}
$controllers[$appRouteKey] = new $appHandler->className;
$log = "OK - Class ".$appHandler->className;
$controllers[$appRouteKey] = ($this->container() instanceof ContainerInterface) ? $this->container()->get($appHandler->className) : new $appHandler->className;
$log = "Class ".$appHandler->className;
if(!empty($appHandler->methodName)){
if(!method_exists($appHandler->className, $appHandler->methodName)) {
@@ -55,9 +58,9 @@ class App extends Main {
continue;
}
$response = (!empty($appHandler->params)) ? $controllers[$appRouteKey]->{$appHandler->methodName}(...$appHandler->params) : $controllers[$appRouteKey]->{$appHandler->methodName}();
$log = "OK - Method ".$appHandler->className."/".$appHandler->methodName;
$log = "Method ".$appHandler->className."/".$appHandler->methodName;
}
$this->syslogger()->log("handlers", $log);
$this->syslogger()->log("handlers", "OK - ".$log);
/**
* 1. Если на этапе итерации уже получен ответ ResponseInterface - досрочно отдаем результат в эмиттер
*/
@@ -85,7 +88,7 @@ class App extends Main {
if($this->logger()) $this->logger()->warning($appException->getMessage()." on ".$appException->getFile().":".$appException->getLine());
$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());
$this->syslogger()->warning("Exception: ".$exception->getMessage()." : ".$exception->getFile()." : ".$exception->getLine());
}
@@ -155,11 +158,6 @@ class App extends Main {
if(is_file($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();
$this->getActions($nodes);
}
@@ -170,7 +168,7 @@ class App extends Main {
private function getActions(array $appNodes) : void {
foreach ($appNodes as $appNode){
// по умолчанию точка монтирования ровна корню
// по умолчанию точка монтирования от корня
$mountKey = (!empty($appNode['key'])) ? $appNode['key'] : '/';
// если url начинается не с точки монтирования смотрим далее
@@ -190,9 +188,6 @@ class App extends Main {
if(pathinfo($this->baseDir."/".$appNode['router'])['extension'] == "php") {
$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") {
$this->router->withRules(yaml_parse_file($this->baseDir."/".$appNode['router']));
}