Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9fb52d116d | ||
|
|
1ffad8d84a | ||
|
|
1d37f96799 | ||
|
|
e500d67171 | ||
|
|
cf621dbaef | ||
|
|
5eaf931847 |
@@ -11,5 +11,5 @@ composer require rmphp/kernel
|
|||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer require rmphp/kernel:"^3.0"
|
composer require rmphp/kernel:"^5.0"
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -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": "^2.0"
|
"rmphp/foundation": "^2.1"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
21
src/App.php
21
src/App.php
@@ -82,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) {
|
||||||
@@ -166,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){
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ class Globals {
|
|||||||
|
|
||||||
private ServerRequestInterface $request;
|
private ServerRequestInterface $request;
|
||||||
private ResponseInterface $response;
|
private ResponseInterface $response;
|
||||||
private Session $session;
|
|
||||||
|
|
||||||
const INT = "INT";
|
const INT = "INT";
|
||||||
const STRING = "STRING";
|
const STRING = "STRING";
|
||||||
@@ -84,16 +83,6 @@ class Globals {
|
|||||||
return (!empty($name)) ? isset($this->request->getCookieParams()[$name]) : !empty($this->request->getCookieParams());
|
return (!empty($name)) ? isset($this->request->getCookieParams()[$name]) : !empty($this->request->getCookieParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isSession(string $name = "") : bool {
|
|
||||||
if(!class_exists(Session::class)) return false;
|
|
||||||
if(!isset($this->session)) $this->session = new Session();
|
|
||||||
return (!empty($name)) ? isset($this->session->getSession()[$name]) : !empty($this->session->getSession());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return bool
|
* @return bool
|
||||||
@@ -138,17 +127,6 @@ class Globals {
|
|||||||
return $this->onGlobal($this->request->getCookieParams(), $name, $type);
|
return $this->onGlobal($this->request->getCookieParams(), $name, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param string $type
|
|
||||||
* @return array|int|string
|
|
||||||
*/
|
|
||||||
public function session(string $name = "", string $type = "") {
|
|
||||||
if(!class_exists(Session::class)) return null;
|
|
||||||
if(!isset($this->session)) $this->session = new Session();
|
|
||||||
return $this->onGlobal($this->session->getSession(), $name, $type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return array|UploadedFileInterface|null
|
* @return array|UploadedFileInterface|null
|
||||||
@@ -182,18 +160,6 @@ class Globals {
|
|||||||
$this->setResponse($this->response->withAddedHeader($name, $value));
|
$this->setResponse($this->response->withAddedHeader($name, $value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param $value
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setSession(string $name, $value = null) : void {
|
|
||||||
if(class_exists(Session::class)) {
|
|
||||||
if(!isset($this->session)) $this->session = new Session();
|
|
||||||
$this->session->setSession($name, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $value
|
* @param string $value
|
||||||
@@ -217,17 +183,6 @@ class Globals {
|
|||||||
$this->addHeader("Set-Cookie", implode("; ", $cookie));
|
$this->addHeader("Set-Cookie", implode("; ", $cookie));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string|null $name
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function clearSession(string $name = null) : void{
|
|
||||||
if(class_exists(Session::class)) {
|
|
||||||
if(!isset($this->session)) $this->session = new Session();
|
|
||||||
$this->session->clearSession($name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $path
|
* @param string $path
|
||||||
@@ -240,14 +195,13 @@ class Globals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $var
|
* @param array $var
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @return array|int|string
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private function onGlobal(array $var, string $name, string $type = "") {
|
private function onGlobal(array $var, string $name, string $type = ""): mixed {
|
||||||
$name = strtolower($name);
|
$name = strtolower($name);
|
||||||
if (!empty($name))
|
if (!empty($name))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Rmphp\Kernel;
|
|
||||||
|
|
||||||
|
|
||||||
class Session {
|
|
||||||
|
|
||||||
public function __construct(string $name = "usi") {
|
|
||||||
if(session_status() == PHP_SESSION_NONE) {
|
|
||||||
session_name($name);
|
|
||||||
session_start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getSession() : array {
|
|
||||||
return $_SESSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param $value
|
|
||||||
*/
|
|
||||||
public function setSession(string $name, $value = null) : void {
|
|
||||||
$_SESSION[$name] = $value;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string|null $name
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function clearSession(string $name = null) : void {
|
|
||||||
if (isset($name)) unset($_SESSION[$name]);
|
|
||||||
else $_SESSION = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user