Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d5538ad35 | ||
|
|
c2a14307ae | ||
|
|
ddb82ee395 | ||
|
|
a095b76e8d | ||
|
|
70810412f4 | ||
|
|
fee7f1466c | ||
|
|
a05a8c8dd1 | ||
|
|
133371a908 | ||
|
|
49ae47e43e | ||
|
|
8fc94aaeb8 | ||
|
|
aba089db5e | ||
|
|
43e529dcad | ||
|
|
5bef4f577e | ||
|
|
b53c3f9815 | ||
|
|
11b1544317 | ||
|
|
9e4ae35455 | ||
|
|
23133c173c | ||
|
|
bf529d83c8 |
@@ -10,9 +10,10 @@
|
|||||||
|
|
||||||
# PROD / DEV
|
# PROD / DEV
|
||||||
APP_MODE=DEV
|
APP_MODE=DEV
|
||||||
APP_NODES_FILE=application/config/app.php
|
APP_NODES_FILE=config/app.php
|
||||||
APP_COMPONENTS_FILE=application/config/components.php
|
CLI_NODES_FILE=config/app-cli.php
|
||||||
CONTAINER_INI=application/config/container.php
|
APP_COMPONENTS_FILE=config/components.php
|
||||||
|
CONTAINER_INI=config/container.php
|
||||||
CONTAINER_CACHE=var/cache/container
|
CONTAINER_CACHE=var/cache/container
|
||||||
|
|
||||||
# Default page
|
# Default page
|
||||||
@@ -21,3 +22,4 @@ 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.1" project-name
|
composer create-project rmphp/skeleton:"^4.10" project-name
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -2,26 +2,40 @@
|
|||||||
|
|
||||||
namespace Base\Application;
|
namespace Base\Application;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use ReflectionClass;
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
abstract class AbstractDTO {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return static
|
* @return static
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
static function fromArray(array $data) : static {
|
public static function fromArray(array $data) : static {
|
||||||
$class = new ReflectionClass(static::class);
|
return self::fillObject(new ReflectionClass(static::class), new static(), $data);
|
||||||
$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,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: Zuev Yuri
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Base\Domain;
|
|
||||||
|
|
||||||
abstract class AbstractObject implements EntityInterface {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int|null
|
|
||||||
*/
|
|
||||||
public function getId(): mixed {
|
|
||||||
return (isset($this->id)) ? (($this->id instanceof ValueObjectInterface) ? $this->id->get() : $this->id) : null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: Zuev Yuri
|
|
||||||
* Date: 23.04.2024
|
|
||||||
* Time: 3:58
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Base\Domain;
|
|
||||||
|
|
||||||
interface EntityInterface {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int|null
|
|
||||||
*/
|
|
||||||
public function getId(): mixed;
|
|
||||||
|
|
||||||
}
|
|
||||||
0
application/base/Domain/ValueObject/.gitkeep
Normal file
0
application/base/Domain/ValueObject/.gitkeep
Normal file
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: Zuev Yuri
|
|
||||||
* Date: 23.04.2024
|
|
||||||
* Time: 3:58
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Base\Domain;
|
|
||||||
|
|
||||||
interface ValueObjectInterface {
|
|
||||||
|
|
||||||
public function get();
|
|
||||||
public function __toString(): string;
|
|
||||||
|
|
||||||
}
|
|
||||||
71
application/base/Handlers/AbstractHandler.php
Normal file
71
application/base/Handlers/AbstractHandler.php
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Base\Handlers;
|
||||||
|
|
||||||
|
use Laminas\Diactoros\Response\HtmlResponse;
|
||||||
|
use Laminas\Diactoros\Response\JsonResponse;
|
||||||
|
use Laminas\Diactoros\Response\TextResponse;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Rmphp\Kernel\Main;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
abstract class AbstractHandler extends Main {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Throwable $throwable
|
||||||
|
* @param array $data
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function logException(Throwable $throwable, array $data = []) : void {
|
||||||
|
$this->logger()->warning($throwable->getMessage()." on ".$throwable->getFile().":".$throwable->getLine(), $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Throwable $throwable
|
||||||
|
* @param array $data
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function logError(Throwable $throwable, array $data = []) : void {
|
||||||
|
$this->logger()->error($throwable->getMessage()." on ".$throwable->getFile().":".$throwable->getLine(), $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param string $value
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addHeader(string $name, string $value) : void {
|
||||||
|
$this->globals()->addHeader($name, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $html
|
||||||
|
* @param int $status
|
||||||
|
* @param array $headers
|
||||||
|
* @return ResponseInterface
|
||||||
|
*/
|
||||||
|
public function htmlResponse($html, int $status = 200, array $headers = []) : ResponseInterface {
|
||||||
|
return new HtmlResponse($html, $status, array_merge($this->globals()->response()->getHeaders(), $headers));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $text
|
||||||
|
* @param int $status
|
||||||
|
* @param array $headers
|
||||||
|
* @return ResponseInterface
|
||||||
|
*/
|
||||||
|
public function textResponse($text, int $status = 200, array $headers = []) : ResponseInterface {
|
||||||
|
return new TextResponse($text, $status, array_merge($this->globals()->response()->getHeaders(), $headers));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $array
|
||||||
|
* @param int $status
|
||||||
|
* @param array $headers
|
||||||
|
* @return ResponseInterface
|
||||||
|
*/
|
||||||
|
public function jsonResponse(array $array, int $status = 200, array $headers = []) : ResponseInterface {
|
||||||
|
return new JsonResponse($array, $status, array_merge($this->globals()->response()->getHeaders(), $headers), JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
0
application/base/Repository/.gitkeep
Normal file
0
application/base/Repository/.gitkeep
Normal file
@@ -1,37 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Base\Repository;
|
|
||||||
|
|
||||||
use Base\Domain\EntityInterface;
|
|
||||||
use Rmphp\Storage\Mysql\MysqlStorageInterface;
|
|
||||||
|
|
||||||
abstract class AbstractMysqlRepository extends AbstractRepository {
|
|
||||||
|
|
||||||
public const DEBUG = false;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
public readonly MysqlStorageInterface $mysql
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param EntityInterface $object
|
|
||||||
* @param string $table
|
|
||||||
* @return mixed
|
|
||||||
* @throws RepositoryException
|
|
||||||
*/
|
|
||||||
public function saveEntity(EntityInterface $object, string $table) : mixed {
|
|
||||||
$in = $this->getProperties($object, function ($value){
|
|
||||||
return (is_string($value)) ? $this->mysql->escapeStr($value) : $value;
|
|
||||||
});
|
|
||||||
if(static::DEBUG) dd($object, $in, $table);
|
|
||||||
try {
|
|
||||||
if (!empty($object->getId()) && !empty($this->mysql->findById($table, $object->getId()))) {
|
|
||||||
$this->mysql->updateById($table, $in, $object->getId());
|
|
||||||
return $object->getId();
|
|
||||||
} else {
|
|
||||||
$this->mysql->insert($table, $in);
|
|
||||||
return (is_string($object->getId())) ? $object->getId() : $this->mysql->mysql()->insert_id;
|
|
||||||
}
|
|
||||||
} catch (\Throwable $throwable) {throw new RepositoryException($throwable->getMessage());}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
### Создание объекта из массива
|
|
||||||
|
|
||||||
```php
|
|
||||||
setProperties(array $data) : void
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### Получение массива из объекта
|
|
||||||
|
|
||||||
```php
|
|
||||||
getProperties(callable $method = null) : array
|
|
||||||
```
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: Zuev Yuri
|
|
||||||
* Date: 25.04.2024
|
|
||||||
* Time: 13:06
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Base\Repository;
|
|
||||||
|
|
||||||
use Base\Domain\ValueObjectInterface;
|
|
||||||
use ReflectionClass;
|
|
||||||
use ReflectionException;
|
|
||||||
|
|
||||||
class AbstractRepository {
|
|
||||||
|
|
||||||
static array $classes = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $class
|
|
||||||
* @param $data
|
|
||||||
* @return mixed
|
|
||||||
* @throws RepositoryException
|
|
||||||
*/
|
|
||||||
public function create(string $class, $data) : mixed {
|
|
||||||
try {
|
|
||||||
if(!isset(static::$classes[$class])) static::$classes[$class] = new ReflectionClass($class);
|
|
||||||
$object = new $class;
|
|
||||||
foreach (static::$classes[$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(static::$classes[$class]->hasMethod('set'.ucfirst($property->getName()))) $object->{'set'.ucfirst($property->getName())}($value);
|
|
||||||
// Если тип свойства класс (valueObject)
|
|
||||||
elseif($property->hasType() && class_exists($property->getType()->getName())) $object->{$property->getName()} = new ($property->getType()->getName())($value);
|
|
||||||
// если значения не пустое
|
|
||||||
elseif(isset($value)) $object->{$property->getName()} = $value;
|
|
||||||
}
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
catch (ReflectionException $exception) {
|
|
||||||
throw new RepositoryException($exception->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param object $class
|
|
||||||
* @param callable|null $method
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getProperties(object $class, callable $method = null) : array {
|
|
||||||
|
|
||||||
$objectData = get_object_vars($class);
|
|
||||||
foreach ($objectData as $fieldName => $value)
|
|
||||||
{
|
|
||||||
// to option_id
|
|
||||||
$fieldNameSnakeCase = strtolower(preg_replace("'([A-Z])'", "_$1", $fieldName));
|
|
||||||
|
|
||||||
// если есть внутренний метод (приоритетная обработка)
|
|
||||||
if(method_exists($this, 'get'.ucfirst($fieldName))) {
|
|
||||||
$out[$fieldNameSnakeCase] = $this->{'get'.ucfirst($fieldName)}($value);
|
|
||||||
}
|
|
||||||
// если тип свойства класс (valueObject)
|
|
||||||
elseif($value instanceof ValueObjectInterface && null !== $value->get()) {
|
|
||||||
$out[$fieldNameSnakeCase] = $value->get();
|
|
||||||
}
|
|
||||||
// если передана callable функция через которую нужно пропустить все элементы
|
|
||||||
elseif(isset($method) && !is_array($value) && !is_object($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,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Base\Repository;
|
|
||||||
|
|
||||||
use Throwable;
|
|
||||||
|
|
||||||
class RepositoryException 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
application/bin/cli
Normal file
3
application/bin/cli
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/php
|
||||||
|
<?php
|
||||||
|
require_once dirname(__FILE__).'/cli.php';
|
||||||
13
application/bin/cli.php
Normal file
13
application/bin/cli.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Laminas\Diactoros\Response;
|
||||||
|
use Laminas\Diactoros\ServerRequestFactory;
|
||||||
|
use Rmphp\Kernel\AppCli;
|
||||||
|
use Rmphp\Kernel\ResponseEmitter;
|
||||||
|
|
||||||
|
require_once dirname(__DIR__,2).'/vendor/autoload.php';
|
||||||
|
(new Symfony\Component\Dotenv\Dotenv())->usePutenv()->loadEnv(dirname(__DIR__,2).'/.env');
|
||||||
|
|
||||||
|
$app = new AppCli();
|
||||||
|
$response = $app->handler(ServerRequestFactory::fromGlobals(), new Response());
|
||||||
|
(new ResponseEmitter())->emit($response);
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
return [
|
|
||||||
"application/config/container/services.php",
|
|
||||||
"application/config/container/settings.php",
|
|
||||||
];
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
<?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\MysqlStorageInterface;
|
|
||||||
|
|
||||||
return [
|
|
||||||
MysqlStorageInterface::class => DI\create(MysqlStorage::class)->constructor(json_decode(getenv("MYSQL_PARAM"), true)),
|
|
||||||
SessionInterface::class => DI\create(Session::class)->constructor(),
|
|
||||||
CacheInterface::class => DI\create(Cache::class)->constructor("../var/cache"),
|
|
||||||
'App\*\Domain\Repository\*RepositoryInterface' => DI\autowire('App\*\Infrastructure\Repository\*Repository'),
|
|
||||||
];
|
|
||||||
@@ -12,12 +12,12 @@
|
|||||||
"monolog/monolog": "^2.3",
|
"monolog/monolog": "^2.3",
|
||||||
"php-di/php-di": "^6.3",
|
"php-di/php-di": "^6.3",
|
||||||
"ramsey/uuid": "^4.7",
|
"ramsey/uuid": "^4.7",
|
||||||
"rmphp/cache-file": "^1.0",
|
"rmphp/content": "^4.0",
|
||||||
"rmphp/content": "^3.1",
|
"rmphp/kernel": "^6.0",
|
||||||
"rmphp/kernel": "^4.1",
|
"rmphp/router": "^2.0",
|
||||||
"rmphp/router": "^1.2",
|
"rmphp/session": "^1.1",
|
||||||
"rmphp/session": "^1.0",
|
"rmphp/redis": "^1.0",
|
||||||
"rmphp/storage": "^3.1",
|
"rmphp/storage": "^8.0",
|
||||||
"symfony/dotenv": "^6.2"
|
"symfony/dotenv": "^6.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|||||||
19
config/app-cli.php
Normal file
19
config/app-cli.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
# Example:
|
||||||
|
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
|
||||||
|
# ['key'=>'', 'router'=>'config/routes-cli/routes.php'],
|
||||||
|
# ['key'=>'/', 'router'=>[]],
|
||||||
|
|
||||||
|
return [
|
||||||
|
['key'=>'', 'router'=>[
|
||||||
|
[
|
||||||
|
'key'=>'index',
|
||||||
|
'routes' => [
|
||||||
|
[
|
||||||
|
'action' => "App\Infrastructure\Handlers\IndexHandler",
|
||||||
|
'method' => "index"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]],
|
||||||
|
];
|
||||||
@@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
# Example:
|
# Example:
|
||||||
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
|
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
|
||||||
# ['key'=>'/', 'router'=>'application/config/routes/main/routes.php'],
|
# ['key'=>'/', 'router'=>'config/routes/main/routes.php'],
|
||||||
# ['key'=>'/', 'router'=>[]],
|
# ['key'=>'/', 'router'=>[]],
|
||||||
|
|
||||||
return [
|
return [
|
||||||
['key'=>'/', 'router'=>'application/config/routes/routes.php'],
|
['key'=>'/', 'router'=>'config/routes/routes.php'],
|
||||||
];
|
];
|
||||||
@@ -4,17 +4,17 @@ return [
|
|||||||
/**
|
/**
|
||||||
* Путь к файлу фабрики возвращающий реализацию RouterInterface или сам экземпляр класса
|
* Путь к файлу фабрики возвращающий реализацию RouterInterface или сам экземпляр класса
|
||||||
*/
|
*/
|
||||||
\Rmphp\Foundation\RouterInterface::class => 'application/config/components/routerFactory.php',
|
\Rmphp\Foundation\RouterInterface::class => 'config/components/routerFactory.php',
|
||||||
/**
|
/**
|
||||||
* Путь к файлу фабрики возвращающий реализацию TemplateInterface или сам экземпляр класса
|
* Путь к файлу фабрики возвращающий реализацию TemplateInterface или сам экземпляр класса
|
||||||
*/
|
*/
|
||||||
\Rmphp\Foundation\TemplateInterface::class => 'application/config/components/templateFactory.php',
|
\Rmphp\Foundation\TemplateInterface::class => 'config/components/templateFactory.php',
|
||||||
/**
|
/**
|
||||||
* Путь к файлу фабрики возвращающий реализацию PSR-3 LoggerInterface или сам экземпляр класса
|
* Путь к файлу фабрики возвращающий реализацию PSR-3 LoggerInterface или сам экземпляр класса
|
||||||
*/
|
*/
|
||||||
\Psr\Log\LoggerInterface::class => 'application/config/components/loggerFactory.php',
|
\Psr\Log\LoggerInterface::class => 'config/components/loggerFactory.php',
|
||||||
/**
|
/**
|
||||||
* Путь к файлу фабрики возвращающий реализацию PSR-11 ContainerInterface или сам экземпляр класса
|
* Путь к файлу фабрики возвращающий реализацию PSR-11 ContainerInterface или сам экземпляр класса
|
||||||
*/
|
*/
|
||||||
\Psr\Container\ContainerInterface::class => 'application/config/components/containerFactory.php',
|
\Psr\Container\ContainerInterface::class => 'config/components/containerFactory.php',
|
||||||
];
|
];
|
||||||
@@ -2,18 +2,18 @@
|
|||||||
|
|
||||||
use DI\ContainerBuilder;
|
use DI\ContainerBuilder;
|
||||||
|
|
||||||
$containerIni = (getenv("CONTAINER_INI")) ?: "application/config/container.php";
|
$containerIni = (getenv("CONTAINER_INI")) ?: "config/container.php";
|
||||||
$containerCache = (getenv("CONTAINER_CACHE")) ?: "var/cache/container";
|
$containerCache = (getenv("CONTAINER_CACHE")) ?: "var/cache/container";
|
||||||
|
|
||||||
$dependencies = require dirname(__DIR__,3).'/'.$containerIni;
|
$dependencies = require dirname(__DIR__,2).'/'.$containerIni;
|
||||||
|
|
||||||
$dependenciesCollection = array_map(function ($dependenciesFile){
|
$dependenciesCollection = array_map(function ($dependenciesFile){
|
||||||
return require dirname(__DIR__,3)."/".$dependenciesFile;
|
return require dirname(__DIR__,2)."/".$dependenciesFile;
|
||||||
}, $dependencies);
|
}, $dependencies);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$builder = new ContainerBuilder();
|
$builder = new ContainerBuilder();
|
||||||
if(getenv("APP_MODE") == "PROD") $builder->enableCompilation(dirname(__DIR__,3)."/".$containerCache);
|
if(getenv("APP_MODE") == "PROD") $builder->enableCompilation(dirname(__DIR__,2)."/".$containerCache);
|
||||||
$builder->addDefinitions(array_replace_recursive(...$dependenciesCollection));
|
$builder->addDefinitions(array_replace_recursive(...$dependenciesCollection));
|
||||||
return $builder->build();
|
return $builder->build();
|
||||||
} catch (Exception $e) {echo $e->getMessage();}
|
} catch (Exception $e) {echo $e->getMessage();}
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
<?php
|
<?php
|
||||||
return (new \Monolog\Logger('system'))->pushHandler(new \Monolog\Handler\StreamHandler(dirname(__DIR__, 3).'/var/logs/log'.date('Ymd').'.log'));
|
return (new \Monolog\Logger('system'))->pushHandler(new \Monolog\Handler\StreamHandler(dirname(__DIR__, 2).'/var/logs/log'.date('Ymd').'.log'));
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
return (new \Rmphp\Content\Content('/templates/base.tpl'))->setSubtemplatePath('/templates/')->setSubtemplatePathAlias([
|
return (new \Rmphp\Content\Content('/templates/base.tpl'))->setSubtemplatePath('/templates/')->setSubtemplatePathAlias([
|
||||||
"main" => "/src/Infrastructure/templates",
|
"main" => "/src/Infrastructure/subtemplates",
|
||||||
]);
|
]);
|
||||||
5
config/container.php
Normal file
5
config/container.php
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
"config/container/services.php",
|
||||||
|
"config/container/settings.php",
|
||||||
|
];
|
||||||
10
config/container/services.php
Normal file
10
config/container/services.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Rmphp\Storage\Mysql\MysqlStorage;
|
||||||
|
use Rmphp\Storage\Mysql\MysqlStorageInterface;
|
||||||
|
|
||||||
|
return [
|
||||||
|
MysqlStorageInterface::class => DI\create(MysqlStorage::class)->constructor(json_decode(getenv("MYSQL_PARAM"))),
|
||||||
|
'App\Domain\Repository\*RepositoryInterface' => DI\autowire('App\Infrastructure\Repository\*Repository'),
|
||||||
|
'App\*\Domain\Repository\*RepositoryInterface' => DI\autowire('App\*\Infrastructure\Repository\*Repository'),
|
||||||
|
];
|
||||||
@@ -8,6 +8,6 @@
|
|||||||
# Empty
|
# Empty
|
||||||
- key: "<@any>"
|
- key: "<@any>"
|
||||||
routes:
|
routes:
|
||||||
- action: "App\\nfrastructure\\Controllers\\IndexController"
|
- action: "App\\Infrastructure\\Controllers\\IndexController"
|
||||||
method: "emptyAction"
|
method: "emptyAction"
|
||||||
params: ""
|
params: ""
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$cashFile = preg_replace("'.application.*$'",'', __DIR__).'/var/routes/'.md5(__FILE__);
|
$cashFile = dirname(__DIR__,2).'/var/routes/'.md5(__FILE__);
|
||||||
|
|
||||||
if(getenv("APP_MODE") == "PROD" && file_exists($cashFile)){
|
if(getenv("APP_MODE") == "PROD" && file_exists($cashFile)){
|
||||||
return unserialize(file_get_contents($cashFile));
|
return unserialize(file_get_contents($cashFile));
|
||||||
22
src/Infrastructure/Handlers/IndexHandler.php
Normal file
22
src/Infrastructure/Handlers/IndexHandler.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: Zuev Yuri
|
||||||
|
* Date: 02.03.2025
|
||||||
|
* Time: 22:02
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Infrastructure\Handlers;
|
||||||
|
|
||||||
|
use Base\Handlers\AbstractHandler;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
|
class IndexHandler extends AbstractHandler {
|
||||||
|
|
||||||
|
public function index() : bool|ResponseInterface {
|
||||||
|
|
||||||
|
return $this->textResponse((new \DateTime())->format('Y-m-d H:i:s'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user