10 Commits
2.0 ... 4.1

Author SHA1 Message Date
User
1d37f96799 20240502#3 2024-05-02 11:22:52 +03:00
User
e500d67171 20240502#2 2024-05-02 11:21:57 +03:00
User
cf621dbaef 20240412#1 2024-04-12 02:43:39 +03:00
User
5eaf931847 20240410#8 2024-04-10 03:36:09 +03:00
User
efe3b0ad5a 20240410#4 2024-04-10 02:37:25 +03:00
User
d9a3deef90 20231113#2 2023-11-13 04:13:49 +03:00
User
0c121af290 20231113#1 2023-11-13 04:12:41 +03:00
User
7b03cf952e 20231010#7 2023-10-11 00:03:51 +03:00
User
33e3fba104 20231010#6 2023-10-11 00:00:54 +03:00
User
2a620798b3 20231009#1 2023-10-09 14:12:18 +03:00
4 changed files with 30 additions and 31 deletions

View File

@@ -11,5 +11,5 @@ composer require rmphp/kernel
``` ```
```bash ```bash
composer require rmphp/kernel:"^2.0" composer require rmphp/kernel:"^4.1"
``` ```

View File

@@ -12,7 +12,7 @@
"ext-yaml": "*", "ext-yaml": "*",
"psr/log": "^3.0.0", "psr/log": "^3.0.0",
"psr/container": "^1.0", "psr/container": "^1.0",
"rmphp/foundation": "^1.0" "rmphp/foundation": "^2.1"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View File

@@ -61,9 +61,7 @@ class App extends Main {
$log = "Method ".$appHandler->className."/".$appHandler->methodName; $log = "Method ".$appHandler->className."/".$appHandler->methodName;
} }
$this->syslogger()->log("handlers", "OK - ".$log); $this->syslogger()->log("handlers", "OK - ".$log);
/**
* 1. Если на этапе итерации уже получен ответ ResponseInterface - досрочно отдаем результат в эмиттер
*/
if($response instanceof ResponseInterface) { if($response instanceof ResponseInterface) {
return $response; 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); return $this->defaultPage(404);
} }
@@ -93,7 +82,7 @@ class App extends Main {
$this->syslogger()->warning("Exception: ".$exception->getMessage()." : ".$exception->getFile()." : ".$exception->getLine()); $this->syslogger()->warning("Exception: ".$exception->getMessage()." : ".$exception->getFile()." : ".$exception->getLine());
} }
catch (AppError $appError){ 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()); $this->syslogger()->error("Error: ".$appError->getMessage()." : ".$appError->getFile()." : ".$appError->getLine());
} }
catch (\Error $error) { catch (\Error $error) {
@@ -101,7 +90,7 @@ class App extends Main {
$this->syslogger()->error("Error: ".$error->getMessage()." : ".$error->getFile()." : ".$error->getLine()); $this->syslogger()->error("Error: ".$error->getMessage()." : ".$error->getFile()." : ".$error->getLine());
} }
/** /**
* 4. Отдаем ошибку без шаблона * Отдаем после ошибки
*/ */
return $this->defaultPage(501); return $this->defaultPage(501);
} }
@@ -112,10 +101,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);
} }
@@ -180,17 +166,22 @@ class App extends Main {
$params = (!empty($appNode['params']) && is_string($appNode['params'])) ? explode(",",str_replace(" ", "", $appNode['params'])) : []; $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, $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'])){ elseif(!empty($appNode['router']) && file_exists($this->baseDir."/".$appNode['router'])){
if(empty($this->router)) throw AppError::invalidRequiredObject("Application config without router"); if(empty($this->router)) throw AppError::invalidRequiredObject("Application config without router");
$this->router->setStartPoint($mountKey); $this->router->setStartPoint($mountKey);
ob_start(); $routes = include_once $this->baseDir."/".$appNode['router']; ob_end_clean();
if(pathinfo($this->baseDir."/".$appNode['router'])['extension'] == "php") { if(is_array($routes)) $this->router->withRules($routes);
$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']));
}
$routes = $this->router->match($this->globals()->request()) ?? []; $routes = $this->router->match($this->globals()->request()) ?? [];
foreach ($routes as $route){ foreach ($routes as $route){

View File

@@ -4,6 +4,7 @@ namespace Rmphp\Kernel;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UploadedFileInterface;
class Globals { class Globals {
@@ -150,10 +151,17 @@ class Globals {
/** /**
* @param string $name * @param string $name
* @return array|int|string * @return array|UploadedFileInterface|null
*/ */
public function files(string $name = "") { public function files(string $name = ""): array|UploadedFileInterface|null {
return $this->onGlobal($this->request->getUploadedFiles(), $name); $name = strtolower($name);
$var = $this->request->getUploadedFiles();
if (!empty($name))
{
if (!isset($var[$name])) return null;
return $var[$name];
}
return $var;
} }
/** /**