Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43e529dcad | ||
|
|
5bef4f577e | ||
|
|
b53c3f9815 | ||
|
|
11b1544317 | ||
|
|
9e4ae35455 | ||
|
|
23133c173c | ||
|
|
bf529d83c8 | ||
|
|
794e82f7ce | ||
|
|
035f88ea72 | ||
|
|
1b0af12a46 | ||
|
|
99f78f7362 | ||
|
|
72d2445bb2 | ||
|
|
40e771f1f2 | ||
|
|
858dfd17c0 | ||
|
|
c3e7bc6fc7 | ||
|
|
3ebbe07db6 | ||
|
|
e865eca689 | ||
|
|
e83753471c | ||
|
|
6c571aa358 | ||
|
|
8b92eecba1 | ||
|
|
e03c9bccfc | ||
|
|
88b597d78d | ||
|
|
de10cbae31 | ||
|
|
98c2d37870 | ||
|
|
1258828b2d | ||
|
|
8ef1287567 | ||
|
|
009832a046 |
8
.editorconfig
Normal file
8
.editorconfig
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
root = true
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 4
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
14
.env.dist
14
.env.dist
@@ -10,15 +10,15 @@
|
|||||||
|
|
||||||
# PROD / DEV
|
# PROD / DEV
|
||||||
APP_MODE=DEV
|
APP_MODE=DEV
|
||||||
|
APP_NODES_FILE=application/config/app.php
|
||||||
APP_COMPONENTS_FILE=application/config/app.php
|
APP_COMPONENTS_FILE=application/config/components.php
|
||||||
APP_NODES_FILE=application/config/nodes.php
|
CONTAINER_INI=application/config/container.php
|
||||||
CONTAINER_DIR=application/config/container
|
|
||||||
CONTAINER_CACHE=var/cache/container
|
CONTAINER_CACHE=var/cache/container
|
||||||
|
|
||||||
# Default page
|
# Default page
|
||||||
PAGE404=templates/error/404.tpl
|
PAGE404="/templates/error/404.tpl"
|
||||||
PAGE501=templates/error/501.tpl
|
PAGE501="/templates/error/501.tpl"
|
||||||
|
|
||||||
# Users environment
|
# 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***", "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
|
```bash
|
||||||
composer create-project rmphp/skeleton:"^4.0" project-name
|
composer create-project rmphp/skeleton:"^4.3" project-name
|
||||||
```
|
```
|
||||||
|
|||||||
27
application/base/Application/AbstractDTO.php
Normal file
27
application/base/Application/AbstractDTO.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Base\Application;
|
||||||
|
|
||||||
|
use ReflectionClass;
|
||||||
|
|
||||||
|
abstract class AbstractDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $data
|
||||||
|
* @return static
|
||||||
|
*/
|
||||||
|
static function fromArray(array $data) : static {
|
||||||
|
$class = new ReflectionClass(static::class);
|
||||||
|
$self = new static();
|
||||||
|
foreach ($class->getProperties() as $property) {
|
||||||
|
$propertyNameSnakeCase = strtolower(preg_replace("'([A-Z])'", "_$1", $property->getName()));
|
||||||
|
// data[propertyName] ?? data[property_name] ?? null
|
||||||
|
$value = $data[$property->getName()] ?? $data[$propertyNameSnakeCase] ?? null;
|
||||||
|
// если есть внутренний метод (приоритетная обработка)
|
||||||
|
if($class->hasMethod('set'.ucfirst($property->getName()))) $self->{'set'.ucfirst($property->getName())}($value);
|
||||||
|
// прямое присовение по умолчанию
|
||||||
|
elseif(isset($value)) $self->{$property->getName()} = $value;
|
||||||
|
}
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Base\Repository;
|
|
||||||
|
namespace Base\Application;
|
||||||
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class RepositoryException extends \Exception {
|
class ApplicationException extends \Exception {
|
||||||
|
|
||||||
public array $data;
|
public array $data;
|
||||||
|
|
||||||
@@ -12,4 +13,4 @@ class RepositoryException extends \Exception {
|
|||||||
parent::__construct($message, $code, $previous);
|
parent::__construct($message, $code, $previous);
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Base\Services;
|
namespace Base\Application;
|
||||||
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
@@ -13,4 +13,4 @@ class DTOException extends \Exception {
|
|||||||
parent::__construct($message, $code, $previous);
|
parent::__construct($message, $code, $previous);
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,4 +146,4 @@ abstract class AbstractController extends Main {
|
|||||||
public function getTemplatePath(string $path) : string {
|
public function getTemplatePath(string $path) : string {
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace Base\Controllers;
|
namespace Base\Controllers;
|
||||||
|
|
||||||
use Base\Repository\RepositoryException;
|
use Base\Application\ApplicationException;
|
||||||
use Base\Services\DTOException;
|
use Base\Application\DTOException;
|
||||||
use Base\Services\ServiceException;
|
use Base\Domain\DomainException;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ abstract class AbstractPageController extends AbstractController {
|
|||||||
public function exceptionPage(Exception $exception, array $data = []) : void {
|
public function exceptionPage(Exception $exception, array $data = []) : void {
|
||||||
$this->logException($exception, $data);
|
$this->logException($exception, $data);
|
||||||
$this->syslogger()->warning($exception->getMessage()." on ".$exception->getFile().":".$exception->getLine(), $data);
|
$this->syslogger()->warning($exception->getMessage()." on ".$exception->getFile().":".$exception->getLine(), $data);
|
||||||
$this->template()->setSubtemplate("main", "/templates/error/errpage.tpl", [
|
$this->template()->setSubtemplate("main", "/error/errpage.tpl", [
|
||||||
"errorText" => "<span style='color:red'>Error: ".$exception->getMessage()." (".$exception->getCode().")"."</span>"
|
"errorText" => "<span style='color:red'>Error: ".$exception->getMessage()." (".$exception->getCode().")"."</span>"
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -28,8 +28,8 @@ abstract class AbstractPageController extends AbstractController {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function checkError(Throwable $e) : string {
|
public function checkError(Throwable $e) : string {
|
||||||
if($e instanceof DTOException || $e instanceof ServiceException || $e instanceof RepositoryException) return $e->getMessage();
|
|
||||||
($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();
|
||||||
return "Ошибка. Дата и время: ".date("d-m-Y H:i:s");
|
return "Ошибка. Дата и время: ".date("d-m-Y H:i:s");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,4 +4,4 @@ namespace Base\Controllers;
|
|||||||
|
|
||||||
class NotFoundException extends \Exception {
|
class NotFoundException extends \Exception {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace Base\Domain;
|
||||||
namespace Base\Services;
|
|
||||||
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class ServiceException extends \Exception {
|
class DomainException extends \Exception {
|
||||||
|
|
||||||
public array $data;
|
public array $data;
|
||||||
|
|
||||||
@@ -13,4 +12,4 @@ class ServiceException extends \Exception {
|
|||||||
parent::__construct($message, $code, $previous);
|
parent::__construct($message, $code, $previous);
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Правила для точек монтирования слоев
|
||||||
|
*/
|
||||||
|
|
||||||
|
# Example:
|
||||||
|
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
|
||||||
|
# ['key'=>'/', 'router'=>'application/config/routes/main/routes.php'],
|
||||||
|
# ['key'=>'/', 'router'=>[]],
|
||||||
|
|
||||||
return [
|
return [
|
||||||
/**
|
['key'=>'/', 'router'=>'application/config/routes/routes.php'],
|
||||||
* Путь к файлу фабрики возвращающий реализацию RouterInterface или сам экземпляр класса
|
|
||||||
*/
|
|
||||||
\Rmphp\Foundation\RouterInterface::class => 'application/config/factories/routerFactory.php',
|
|
||||||
/**
|
|
||||||
* Путь к файлу фабрики возвращающий реализацию TemplateInterface или сам экземпляр класса
|
|
||||||
*/
|
|
||||||
\Rmphp\Foundation\TemplateInterface::class => 'application/config/factories/templateFactory.php',
|
|
||||||
/**
|
|
||||||
* Путь к файлу фабрики возвращающий реализацию PSR-3 LoggerInterface или сам экземпляр класса
|
|
||||||
*/
|
|
||||||
\Psr\Log\LoggerInterface::class => 'application/config/factories/loggerFactory.php',
|
|
||||||
/**
|
|
||||||
* Путь к файлу фабрики возвращающий реализацию PSR-11 ContainerInterface или сам экземпляр класса
|
|
||||||
*/
|
|
||||||
\Psr\Container\ContainerInterface::class => 'application/config/factories/containerFactory.php',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
20
application/config/components.php
Normal file
20
application/config/components.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
/**
|
||||||
|
* Путь к файлу фабрики возвращающий реализацию RouterInterface или сам экземпляр класса
|
||||||
|
*/
|
||||||
|
\Rmphp\Foundation\RouterInterface::class => 'application/config/components/routerFactory.php',
|
||||||
|
/**
|
||||||
|
* Путь к файлу фабрики возвращающий реализацию TemplateInterface или сам экземпляр класса
|
||||||
|
*/
|
||||||
|
\Rmphp\Foundation\TemplateInterface::class => 'application/config/components/templateFactory.php',
|
||||||
|
/**
|
||||||
|
* Путь к файлу фабрики возвращающий реализацию PSR-3 LoggerInterface или сам экземпляр класса
|
||||||
|
*/
|
||||||
|
\Psr\Log\LoggerInterface::class => 'application/config/components/loggerFactory.php',
|
||||||
|
/**
|
||||||
|
* Путь к файлу фабрики возвращающий реализацию PSR-11 ContainerInterface или сам экземпляр класса
|
||||||
|
*/
|
||||||
|
\Psr\Container\ContainerInterface::class => 'application/config/components/containerFactory.php',
|
||||||
|
];
|
||||||
@@ -2,12 +2,13 @@
|
|||||||
|
|
||||||
use DI\ContainerBuilder;
|
use DI\ContainerBuilder;
|
||||||
|
|
||||||
$containerDir = (getenv("CONTAINER_DIR")) ?: "application/config/container";
|
$containerIni = (getenv("CONTAINER_INI")) ?: "application/config/container.php";
|
||||||
$containerCache = (getenv("CONTAINER_CACHE"))?:"var/cache/container";
|
$containerCache = (getenv("CONTAINER_CACHE")) ?: "var/cache/container";
|
||||||
|
|
||||||
|
$dependencies = require dirname(__DIR__,3).'/'.$containerIni;
|
||||||
|
|
||||||
$dependencies = glob(dirname(__DIR__,3)."/".$containerDir."/*.php");
|
|
||||||
$dependenciesCollection = array_map(function ($dependenciesFile){
|
$dependenciesCollection = array_map(function ($dependenciesFile){
|
||||||
return require $dependenciesFile;
|
return require dirname(__DIR__,3)."/".$dependenciesFile;
|
||||||
}, $dependencies);
|
}, $dependencies);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
4
application/config/components/templateFactory.php
Normal file
4
application/config/components/templateFactory.php
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?php
|
||||||
|
return (new \Rmphp\Content\Content('/templates/base.tpl'))->setSubtemplatePath('/templates/')->setSubtemplatePathAlias([
|
||||||
|
"main" => "/src/Infrastructure/subtemplates",
|
||||||
|
]);
|
||||||
5
application/config/container.php
Normal file
5
application/config/container.php
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
"application/config/container/services.php",
|
||||||
|
"application/config/container/settings.php",
|
||||||
|
];
|
||||||
@@ -1,15 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Rmphp\Cache\Cache;
|
|
||||||
use Rmphp\Cache\CacheInterface;
|
|
||||||
use Rmphp\Session\Session;
|
|
||||||
use Rmphp\Session\SessionInterface;
|
|
||||||
use Rmphp\Storage\Mysql\MysqlStorage;
|
use Rmphp\Storage\Mysql\MysqlStorage;
|
||||||
use Rmphp\Storage\Mysql\MysqlStorageInterface;
|
use Rmphp\Storage\Mysql\MysqlStorageInterface;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
MysqlStorageInterface::class => DI\create(MysqlStorage::class)->constructor(json_decode(getenv("MYSQL_PARAM"), true)),
|
MysqlStorageInterface::class => DI\create(MysqlStorage::class)->constructor(json_decode(getenv("MYSQL_PARAM"), true)),
|
||||||
SessionInterface::class => DI\create(Session::class)->constructor(),
|
'App\Domain\Repository\*RepositoryInterface' => DI\autowire('App\Infrastructure\Repository\*Repository'),
|
||||||
CacheInterface::class => DI\create(Cache::class)->constructor("../var/cache"),
|
'App\*\Domain\Repository\*RepositoryInterface' => DI\autowire('App\*\Infrastructure\Repository\*Repository'),
|
||||||
'App\*\Domain\Repository\*Repository\*RepositoryInterface' => DI\autowire('App\*\Repository\Mysql\*Repository'),
|
];
|
||||||
];
|
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
<?php
|
|
||||||
return (new \Rmphp\Content\Content('/templates/base.tpl'))->setSubtemplatePath('/templates');
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Правила для точек монтирования слоев
|
|
||||||
*/
|
|
||||||
|
|
||||||
# Example:
|
|
||||||
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
|
|
||||||
# ['key'=>'/', 'router'=>'config/routes/main/routes.php'],
|
|
||||||
# ['key'=>'/', 'router'=>[]],
|
|
||||||
|
|
||||||
return [
|
|
||||||
['key'=>'/', 'router'=>'application/config/routes/main/routes.php'],
|
|
||||||
];
|
|
||||||
|
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
# Index
|
# Index
|
||||||
- key: "/"
|
- key: "/"
|
||||||
routes:
|
routes:
|
||||||
- action: "App\\Main\\Controllers\\IndexController"
|
- action: "App\\Infrastructure\\Controllers\\IndexController"
|
||||||
method: "index"
|
method: "index"
|
||||||
params: ""
|
params: ""
|
||||||
|
|
||||||
# Empty
|
# Empty
|
||||||
- key: "<@any>"
|
- key: "<@any>"
|
||||||
routes:
|
routes:
|
||||||
- action: "App\\Main\\Controllers\\IndexController"
|
- action: "App\\Infrastructure\\Controllers\\IndexController"
|
||||||
method: "emptyAction"
|
method: "emptyAction"
|
||||||
params: ""
|
params: ""
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
$routes = glob(__DIR__."/{*.yaml}", GLOB_BRACE);
|
|
||||||
|
|
||||||
$routesCollection = array_map(function ($routesFile){
|
|
||||||
return file_get_contents($routesFile).PHP_EOL;
|
|
||||||
}, $routes);
|
|
||||||
|
|
||||||
return yaml_parse(implode($routesCollection));
|
|
||||||
16
application/config/routes/routes.php
Normal file
16
application/config/routes/routes.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$cashFile = preg_replace("'.application.*$'",'', __DIR__).'/var/routes/'.md5(__FILE__);
|
||||||
|
|
||||||
|
if(getenv("APP_MODE") == "PROD" && file_exists($cashFile)){
|
||||||
|
return unserialize(file_get_contents($cashFile));
|
||||||
|
} else {
|
||||||
|
$routesCollection = array_map(function ($routesFile){
|
||||||
|
return file_get_contents($routesFile).PHP_EOL;
|
||||||
|
}, glob(__DIR__."/{*.yaml}", GLOB_BRACE));
|
||||||
|
|
||||||
|
$routes = yaml_parse(implode($routesCollection));
|
||||||
|
if (!is_dir(dirname($cashFile))) mkdir(dirname($cashFile), 0777, true);
|
||||||
|
file_put_contents($cashFile, serialize($routes));
|
||||||
|
return $routes;
|
||||||
|
}
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: Zuev Yuri
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Base\Domain;
|
|
||||||
|
|
||||||
abstract class AbstractObject {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data
|
|
||||||
* @return static
|
|
||||||
*/
|
|
||||||
public static function fromData(array $data) : static {
|
|
||||||
$self = new static();
|
|
||||||
$self->setProperties($data);
|
|
||||||
return $self;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setProperties(array $data) : self {
|
|
||||||
$propArray = array_keys(get_class_vars(get_class($this)));
|
|
||||||
foreach ($propArray as $propName)
|
|
||||||
{
|
|
||||||
$propNameSnakeCase = strtolower(preg_replace("'([A-Z])'", "_$1", $propName));
|
|
||||||
|
|
||||||
// если в переданном массиве ключ и свойство совпадают optionId = optionId
|
|
||||||
if(isset($data[$propName])) {
|
|
||||||
$this->{$propName} = (method_exists($this, 'set'.ucfirst($propName))) ? $this->{'set'.ucfirst($propName)}($data[$propName]) : $data[$propName];
|
|
||||||
}
|
|
||||||
// если свойство в снэйккесе совподает с ключем в массиве option_id = optionId
|
|
||||||
elseif(isset($data[$propNameSnakeCase])) {
|
|
||||||
$this->{$propName} = (method_exists($this, 'set'.ucfirst($propName))) ? $this->{'set'.ucfirst($propName)}($data[$propNameSnakeCase]) : $data[$propNameSnakeCase];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param callable|null $method
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getProperties(callable $method = null) : array {
|
|
||||||
$objectData = get_object_vars($this);
|
|
||||||
foreach ($objectData as $fieldName => $value)
|
|
||||||
{
|
|
||||||
$fieldNameSnakeCase = strtolower(preg_replace("'([A-Z])'", "_$1", $fieldName));
|
|
||||||
|
|
||||||
// если есть внутренний метод
|
|
||||||
if(method_exists($this, 'get'.ucfirst($fieldName))) {
|
|
||||||
$out[$fieldNameSnakeCase] = $this->{'get'.ucfirst($fieldName)}($value);
|
|
||||||
}
|
|
||||||
// если есть callable функция
|
|
||||||
elseif(isset($method) && !is_array($value)) {
|
|
||||||
$out[$fieldNameSnakeCase] = $method($value);
|
|
||||||
}
|
|
||||||
// если это логическое значение
|
|
||||||
elseif(is_bool($value)){
|
|
||||||
$out[$fieldNameSnakeCase] = (int) $value;
|
|
||||||
}
|
|
||||||
// если это дробное число
|
|
||||||
elseif(is_float($value)) {
|
|
||||||
$out[$fieldNameSnakeCase] = $value;
|
|
||||||
}
|
|
||||||
// если это целое число
|
|
||||||
elseif(is_int($value)) {
|
|
||||||
$out[$fieldNameSnakeCase] = $value;
|
|
||||||
}
|
|
||||||
// если это строка
|
|
||||||
elseif(is_string($value)) {
|
|
||||||
$out[$fieldNameSnakeCase] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return $out ?? [];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Base\Repository;
|
|
||||||
|
|
||||||
use Base\Domain\AbstractObject;
|
|
||||||
use Rmphp\Storage\Mysql\MysqlStorageInterface;
|
|
||||||
|
|
||||||
abstract class AbstractMysqlRepository {
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
public readonly MysqlStorageInterface $mysql
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws RepositoryException
|
|
||||||
*/
|
|
||||||
public function saveEntity(AbstractObject $object, string $table) : AbstractObject {
|
|
||||||
$in = $object->getProperties(function ($value){
|
|
||||||
return (is_string($value)) ? $this->mysql->escapeStr($value) : $value;
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
if (!empty($object->id) && !empty($this->mysql->findById($table, $object->id))) {
|
|
||||||
$this->mysql->updateById($table, $in, $object->id);
|
|
||||||
} else {
|
|
||||||
$this->mysql->insert($table, $in);
|
|
||||||
$object->id = $this->mysql->mysql()->insert_id;
|
|
||||||
}
|
|
||||||
} catch (\Throwable $throwable) {throw new RepositoryException($throwable->getMessage());}
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Base\Services;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
abstract class AbstractDTO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data
|
|
||||||
* @return static
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
static function fromArray(array $data) : static {
|
|
||||||
$self = new static();
|
|
||||||
|
|
||||||
$propArray = array_keys(get_class_vars(get_class($self)));
|
|
||||||
|
|
||||||
foreach($propArray as $propName){
|
|
||||||
$propNameSnakeCase = strtolower(preg_replace("'([A-Z])'", "_$1", $propName));
|
|
||||||
if(method_exists($self, "requireAssert".ucfirst($propName))){
|
|
||||||
if(isset($data[$propName])) {
|
|
||||||
$self->{"requireAssert".ucfirst($propName)}($data[$propName]);
|
|
||||||
}
|
|
||||||
elseif(isset($data[$propNameSnakeCase])) {
|
|
||||||
$self->{"requireAssert".ucfirst($propName)}($data[$propNameSnakeCase]);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
throw new DTOException("Отсутствует обязательное значение");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach($data as $key => $item){
|
|
||||||
try {
|
|
||||||
$camelCaseKey = str_replace('_', '', ucwords($key, "_"));
|
|
||||||
if(method_exists($self, "assert".$camelCaseKey)) {
|
|
||||||
$self->{'assert'.$camelCaseKey}($item);
|
|
||||||
} elseif(in_array(lcfirst($camelCaseKey), $propArray)) {
|
|
||||||
$self->{lcfirst($camelCaseKey)} = $item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (\Error $error) {
|
|
||||||
$errorKey[$key] = $error->getMessage();
|
|
||||||
}
|
|
||||||
if(!empty($errorKey)) throw new Exception(json_encode(["data"=>$data, "error"=>$errorKey]));
|
|
||||||
}
|
|
||||||
return $self;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function validateInt($value) : bool {
|
|
||||||
return (is_numeric($value));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function validateFloat($value) : bool {
|
|
||||||
return (is_float((float) $value));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function validateBoolean($value) : bool {
|
|
||||||
return (is_bool($value));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function validateEmail($value) : bool {
|
|
||||||
return (filter_var($value, FILTER_VALIDATE_EMAIL));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Base\Services;
|
|
||||||
|
|
||||||
use Rmphp\Kernel\Main;
|
|
||||||
|
|
||||||
abstract class AbstractService extends Main {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -11,18 +11,19 @@
|
|||||||
"laminas/laminas-diactoros": "^2.5",
|
"laminas/laminas-diactoros": "^2.5",
|
||||||
"monolog/monolog": "^2.3",
|
"monolog/monolog": "^2.3",
|
||||||
"php-di/php-di": "^6.3",
|
"php-di/php-di": "^6.3",
|
||||||
"symfony/dotenv": "^6.2",
|
"ramsey/uuid": "^4.7",
|
||||||
"rmphp/kernel": "^4.0",
|
"rmphp/content": "^3.1",
|
||||||
"rmphp/router": "^1.0",
|
"rmphp/kernel": "^5.0",
|
||||||
"rmphp/content": "^3.0",
|
"rmphp/router": "^1.2",
|
||||||
"rmphp/storage": "^3.0",
|
"rmphp/session": "^1.1",
|
||||||
"rmphp/session": "^1.0",
|
"rmphp/redis": "^1.0",
|
||||||
"rmphp/cache-file": "^1.0"
|
"rmphp/storage": "^5.0",
|
||||||
|
"symfony/dotenv": "^6.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"App\\": "src",
|
"App\\": "src",
|
||||||
"Base\\": "application/src"
|
"Base\\": "application/base"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -11,15 +11,19 @@ require_once dirname(__DIR__).'/vendor/autoload.php';
|
|||||||
|
|
||||||
(new Symfony\Component\Dotenv\Dotenv())->usePutenv()->loadEnv(dirname(__DIR__).'/.env');
|
(new Symfony\Component\Dotenv\Dotenv())->usePutenv()->loadEnv(dirname(__DIR__).'/.env');
|
||||||
|
|
||||||
error_reporting(0); ini_set('display_errors','Off');
|
if(getenv("APP_MODE") == 'DEBUG'){
|
||||||
|
error_reporting(E_ALL); ini_set('display_errors','On');
|
||||||
|
} else {
|
||||||
|
error_reporting(0); ini_set('display_errors','Off');
|
||||||
|
}
|
||||||
|
|
||||||
$request = ServerRequestFactory::fromGlobals();
|
$request = ServerRequestFactory::fromGlobals();
|
||||||
|
|
||||||
$app = new App();
|
$app = new App();
|
||||||
$response = $app->handler($request, (new Response())->withHeader("Content-Type", "text/html; charset=utf-8"));
|
$response = $app->handler($request, new Response());
|
||||||
(new ResponseEmitter())->emit($response);
|
(new ResponseEmitter())->emit($response);
|
||||||
|
|
||||||
if(($response->getStatusCode() !== 200 && getenv("APP_MODE") == 'DEV') || in_array("Dev", $response->getHeader("App-Mode"))){
|
if(($response->getStatusCode() !== 200 && getenv("APP_MODE") == 'DEV') || in_array("Dev", $response->getHeader("App-Mode"))){
|
||||||
$app->syslogger()->dump("Response", $response);
|
$app->syslogger()->dump("Response", $response);
|
||||||
addShutdownInfo($app->syslogger()->getLogs());
|
addShutdownInfo($app->syslogger()->getLogs());
|
||||||
}
|
}
|
||||||
|
|||||||
0
src/Infrastructure/Components/.gitkeep
Normal file
0
src/Infrastructure/Components/.gitkeep
Normal file
@@ -1,10 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Main\Controllers;
|
namespace App\Infrastructure\Controllers;
|
||||||
use Base\Controllers\AbstractPageController;
|
use Base\Controllers\AbstractPageController;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
|
|
||||||
class IndexController extends AbstractPageController {
|
class IndexController extends AbstractPageController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,11 +13,12 @@ class IndexController extends AbstractPageController {
|
|||||||
try {
|
try {
|
||||||
//$this->addHeader("App-Mode", "Dev");
|
//$this->addHeader("App-Mode", "Dev");
|
||||||
$this->template()->setValue("title", "Главная");
|
$this->template()->setValue("title", "Главная");
|
||||||
$this->template()->setSubtemplate("main", "/main/index.tpl", [
|
|
||||||
"date" => (new \DateTime())->format('Y-m-d H:i:s')
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
catch(\Throwable $e){$error = $this->checkError($e);}
|
catch(\Throwable $e){$error = $this->checkError($e);}
|
||||||
return $this->render();
|
|
||||||
|
return $this->renderResponse("main", "@main/index.tpl", [
|
||||||
|
"date" => (new \DateTime())->format('Y-m-d H:i:s'),
|
||||||
|
"error" => $error ?? null
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
0
src/Infrastructure/Repository/.gitkeep
Normal file
0
src/Infrastructure/Repository/.gitkeep
Normal file
8
src/Infrastructure/subtemplates/index.tpl
Normal file
8
src/Infrastructure/subtemplates/index.tpl
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<article>
|
||||||
|
<main>
|
||||||
|
<div class="main-block">
|
||||||
|
<div class="main-block__header">Hello</div>
|
||||||
|
<div class="main-block__text">Now is <?= $this->date ?></div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</article>
|
||||||
0
templates/inc/footer.tpl
Normal file
0
templates/inc/footer.tpl
Normal file
12
templates/inc/header.tpl
Normal file
12
templates/inc/header.tpl
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<header class="header">
|
||||||
|
<div class="header__logo">
|
||||||
|
<a class="header__logolink" href="/"> </a>
|
||||||
|
</div>
|
||||||
|
<div class="header__freearea"></div>
|
||||||
|
<div class="header__user"><?=$this->user->fio ?? "Гость"?></div>
|
||||||
|
<div class="header__out">
|
||||||
|
<a href="/?logout">
|
||||||
|
<i class="header__outicon fa-solid fa-right-from-bracket"></i>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<article>
|
|
||||||
<main>
|
|
||||||
<div class="main-block">
|
|
||||||
<div class="main-block__header">Hello</div>
|
|
||||||
<div class="main-block__text">Now is <?=$this->date?></div>
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
</article>
|
|
||||||
Reference in New Issue
Block a user