20241102#1

This commit is contained in:
User
2024-11-02 07:31:03 +03:00
parent 1b0af12a46
commit 035f88ea72
33 changed files with 56 additions and 54 deletions

View File

@@ -0,0 +1,13 @@
<?php
/**
* Правила для точек монтирования слоев
*/
# Example:
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
# ['key'=>'/', 'router'=>'application/config/routes/main/routes.php'],
# ['key'=>'/', 'router'=>[]],
return [
['key'=>'/', 'router'=>'application/config/routes/routes.php'],
];

View 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',
];

View File

@@ -0,0 +1,19 @@
<?php
use DI\ContainerBuilder;
$containerIni = (getenv("CONTAINER_INI")) ?: "application/config/container.php";
$containerCache = (getenv("CONTAINER_CACHE")) ?: "var/cache/container";
$dependencies = require dirname(__DIR__,3).'/'.$containerIni;
$dependenciesCollection = array_map(function ($dependenciesFile){
return require dirname(__DIR__,3)."/".$dependenciesFile;
}, $dependencies);
try {
$builder = new ContainerBuilder();
if(getenv("APP_MODE") == "PROD") $builder->enableCompilation(dirname(__DIR__,3)."/".$containerCache);
$builder->addDefinitions(array_replace_recursive(...$dependenciesCollection));
return $builder->build();
} catch (Exception $e) {echo $e->getMessage();}

View File

@@ -0,0 +1,2 @@
<?php
return (new \Monolog\Logger('system'))->pushHandler(new \Monolog\Handler\StreamHandler(dirname(__DIR__, 3).'/var/logs/log'.date('Ymd').'.log'));

View File

@@ -0,0 +1,2 @@
<?php
return new \Rmphp\Router\Router();

View File

@@ -0,0 +1,4 @@
<?php
return (new \Rmphp\Content\Content('/templates/base.tpl'))->setSubtemplatePath('/templates/')->setSubtemplatePathAlias([
"main" => "/src/Infrastructure/templates",
]);

View File

@@ -0,0 +1,5 @@
<?php
return [
"application/config/container/services.php",
"application/config/container/settings.php",
];

View File

@@ -0,0 +1,15 @@
<?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'),
];

View File

@@ -0,0 +1,5 @@
<?php
return [
//"container key"=>value
];

View File

@@ -0,0 +1,13 @@
# Index
- key: "/"
routes:
- action: "App\\Infrastructure\\Controllers\\IndexController"
method: "index"
params: ""
# Empty
- key: "<@any>"
routes:
- action: "App\\nfrastructure\\Controllers\\IndexController"
method: "emptyAction"
params: ""

View 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;
}