Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2650ab53f | ||
|
|
0558bb121d | ||
|
|
b5ecb1fc86 |
@@ -9,5 +9,5 @@ composer create-project rmphp/skeleton project-name
|
|||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer create-project rmphp/skeleton:"^4.12" 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;
|
namespace Base\Controllers;
|
||||||
|
|
||||||
use Base\Application\ApplicationException;
|
use Base\Application\ApplicationException;
|
||||||
use Base\Application\DTOException;
|
|
||||||
use Base\Domain\DomainException;
|
use Base\Domain\DomainException;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
abstract class AbstractPageController extends AbstractController {
|
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
|
* @param Throwable $e
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function checkError(Throwable $e) : string {
|
public function checkError(Throwable $e) : string {
|
||||||
($e instanceof Exception) ? $this->logException($e) : $this->logError($e);
|
($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");
|
return "Ошибка. Дата и время: ".date("d-m-Y H:i:s");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
"rmphp/router": "^2.0",
|
"rmphp/router": "^2.0",
|
||||||
"rmphp/session": "^1.1",
|
"rmphp/session": "^1.1",
|
||||||
"rmphp/redis": "^1.0",
|
"rmphp/redis": "^1.0",
|
||||||
"rmphp/storage": "^10.0",
|
"rmphp/storage": "^12.0",
|
||||||
"symfony/dotenv": "^6.2"
|
"symfony/dotenv": "^6.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|||||||
Reference in New Issue
Block a user