Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2650ab53f | ||
|
|
0558bb121d | ||
|
|
b5ecb1fc86 | ||
|
|
618d0029fa | ||
|
|
4f38812468 | ||
|
|
b263351289 | ||
|
|
2657310000 |
@@ -8,7 +8,7 @@
|
||||
#
|
||||
# Real environment variables win over .env files.
|
||||
|
||||
# PROD / DEV
|
||||
# DEBUG / DEV / PROD
|
||||
APP_MODE=DEV
|
||||
APP_NODES_FILE=config/app.php
|
||||
CLI_NODES_FILE=config/app-cli.php
|
||||
@@ -21,5 +21,5 @@ PAGE404="/templates/error/404.tpl"
|
||||
PAGE501="/templates/error/501.tpl"
|
||||
|
||||
# Users environment
|
||||
MYSQL_PARAM='{"host":"host.docker.internal", "user":"***user***", "pass":"***password***","base":"***basename***", "logsEnable":true}'
|
||||
MYSQL_PARAM='{"host":"host.docker.internal", "user":"***user***", "pass":"***password***","base":"***basename***", "charset":"utf8mb4", "logsEnable":true}'
|
||||
REDIS_PARAM='{"host":"127.0.0.1","port":6379,"connectTimeout":2.5,"backoff":{"algorithm":1,"base":500,"cap":750}, "database":0, "defaultExpire":300}'
|
||||
|
||||
@@ -9,5 +9,5 @@ composer create-project rmphp/skeleton project-name
|
||||
```
|
||||
|
||||
```bash
|
||||
composer create-project rmphp/skeleton:"^4.10" project-name
|
||||
composer create-project rmphp/skeleton:"^5.1" project-name
|
||||
```
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Base\Application;
|
||||
|
||||
use Exception;
|
||||
use ReflectionClass;
|
||||
use Rmphp\Storage\Component\AbstractDataObject;
|
||||
|
||||
abstract class AbstractDTO extends AbstractDataObject {
|
||||
|
||||
/**
|
||||
* @param array|object ...$data
|
||||
* @return static
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function fromData(array|object ...$data) : static {
|
||||
$array = array_map(function($item) {
|
||||
return (is_object($item)) ? get_object_vars($item) : $item;
|
||||
}, $data);
|
||||
return self::fromArray(array_merge(...$array));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $data
|
||||
* @return static
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function fromObject(object $data) : static {
|
||||
return self::fromArray(get_object_vars($data));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return static
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function fromArray(array $data) : static {
|
||||
return self::fillObject(new ReflectionClass(static::class), new static(), $data);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Base\Application;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class DTOException extends \Exception {
|
||||
|
||||
public array $data;
|
||||
|
||||
public function __construct($message="", $code=0, array $data = [], Throwable $previous=null) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->data = $data;
|
||||
}
|
||||
}
|
||||
@@ -3,33 +3,19 @@
|
||||
namespace Base\Controllers;
|
||||
|
||||
use Base\Application\ApplicationException;
|
||||
use Base\Application\DTOException;
|
||||
use Base\Domain\DomainException;
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
abstract class AbstractPageController extends AbstractController {
|
||||
|
||||
/**
|
||||
* @param Exception $exception
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
public function exceptionPage(Exception $exception, array $data = []) : void {
|
||||
$this->logException($exception, $data);
|
||||
$this->syslogger()->warning($exception->getMessage()." on ".$exception->getFile().":".$exception->getLine(), $data);
|
||||
$this->template()->setSubtemplate("main", "/error/errpage.tpl", [
|
||||
"errorText" => "<span style='color:red'>Error: ".$exception->getMessage()." (".$exception->getCode().")"."</span>"
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Throwable $e
|
||||
* @return string
|
||||
*/
|
||||
public function checkError(Throwable $e) : string {
|
||||
($e instanceof Exception) ? $this->logException($e) : $this->logError($e);
|
||||
if($e instanceof DTOException || $e instanceof DomainException || $e instanceof ApplicationException) return $e->getMessage();
|
||||
if($e instanceof DomainException || $e instanceof ApplicationException) return $e->getMessage();
|
||||
return "Ошибка. Дата и время: ".date("d-m-Y H:i:s");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable" : true,
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
"php": "^8.3",
|
||||
"ext-json": "*",
|
||||
"ext-yaml": "*",
|
||||
"laminas/laminas-diactoros": "^2.5",
|
||||
@@ -17,7 +17,7 @@
|
||||
"rmphp/router": "^2.0",
|
||||
"rmphp/session": "^1.1",
|
||||
"rmphp/redis": "^1.0",
|
||||
"rmphp/storage": "^8.0",
|
||||
"rmphp/storage": "^12.0",
|
||||
"symfony/dotenv": "^6.2"
|
||||
},
|
||||
"autoload": {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
return [
|
||||
"config/container/params.php",
|
||||
"config/container/services.php",
|
||||
"config/container/settings.php",
|
||||
];
|
||||
|
||||
6
config/container/params.php
Normal file
6
config/container/params.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'MYSQL_PARAM' => json_decode(getenv("MYSQL_PARAM"), true),
|
||||
'REDIS_PARAM' => json_decode(getenv("REDIS_PARAM"), true),
|
||||
];
|
||||
@@ -4,7 +4,7 @@ use Rmphp\Storage\Mysql\MysqlStorage;
|
||||
use Rmphp\Storage\Mysql\MysqlStorageInterface;
|
||||
|
||||
return [
|
||||
MysqlStorageInterface::class => DI\create(MysqlStorage::class)->constructor(json_decode(getenv("MYSQL_PARAM"))),
|
||||
MysqlStorageInterface::class => DI\create(MysqlStorage::class)->constructor(DI\get("MYSQL_PARAM")),
|
||||
'App\Domain\Repository\*RepositoryInterface' => DI\autowire('App\Infrastructure\Repository\*Repository'),
|
||||
'App\*\Domain\Repository\*RepositoryInterface' => DI\autowire('App\*\Infrastructure\Repository\*Repository'),
|
||||
];
|
||||
|
||||
@@ -23,7 +23,7 @@ $app = new App();
|
||||
$response = $app->handler($request, new Response());
|
||||
(new ResponseEmitter())->emit($response);
|
||||
|
||||
if(($response->getStatusCode() !== 200 && getenv("APP_MODE") == 'DEV') || in_array("Dev", $response->getHeader("App-Mode"))){
|
||||
if(($response->getStatusCode() !== 200 && in_array(getenv("APP_MODE"), ['DEBUG', 'DEV'])) || in_array("Dev", $response->getHeader("App-Mode"))){
|
||||
$app->syslogger()->dump("Response", $response);
|
||||
addShutdownInfo($app->syslogger()->getLogs());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user