20250303#2
This commit is contained in:
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"
|
||||
]
|
||||
]
|
||||
]
|
||||
]],
|
||||
];
|
||||
13
config/app.php
Normal file
13
config/app.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Правила для точек монтирования слоев
|
||||
*/
|
||||
|
||||
# Example:
|
||||
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
|
||||
# ['key'=>'/', 'router'=>'config/routes/main/routes.php'],
|
||||
# ['key'=>'/', 'router'=>[]],
|
||||
|
||||
return [
|
||||
['key'=>'/', 'router'=>'config/routes/routes.php'],
|
||||
];
|
||||
20
config/components.php
Normal file
20
config/components.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
/**
|
||||
* Путь к файлу фабрики возвращающий реализацию RouterInterface или сам экземпляр класса
|
||||
*/
|
||||
\Rmphp\Foundation\RouterInterface::class => 'config/components/routerFactory.php',
|
||||
/**
|
||||
* Путь к файлу фабрики возвращающий реализацию TemplateInterface или сам экземпляр класса
|
||||
*/
|
||||
\Rmphp\Foundation\TemplateInterface::class => 'config/components/templateFactory.php',
|
||||
/**
|
||||
* Путь к файлу фабрики возвращающий реализацию PSR-3 LoggerInterface или сам экземпляр класса
|
||||
*/
|
||||
\Psr\Log\LoggerInterface::class => 'config/components/loggerFactory.php',
|
||||
/**
|
||||
* Путь к файлу фабрики возвращающий реализацию PSR-11 ContainerInterface или сам экземпляр класса
|
||||
*/
|
||||
\Psr\Container\ContainerInterface::class => 'config/components/containerFactory.php',
|
||||
];
|
||||
19
config/components/containerFactory.php
Normal file
19
config/components/containerFactory.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use DI\ContainerBuilder;
|
||||
|
||||
$containerIni = (getenv("CONTAINER_INI")) ?: "config/container.php";
|
||||
$containerCache = (getenv("CONTAINER_CACHE")) ?: "var/cache/container";
|
||||
|
||||
$dependencies = require dirname(__DIR__,2).'/'.$containerIni;
|
||||
|
||||
$dependenciesCollection = array_map(function ($dependenciesFile){
|
||||
return require dirname(__DIR__,2)."/".$dependenciesFile;
|
||||
}, $dependencies);
|
||||
|
||||
try {
|
||||
$builder = new ContainerBuilder();
|
||||
if(getenv("APP_MODE") == "PROD") $builder->enableCompilation(dirname(__DIR__,2)."/".$containerCache);
|
||||
$builder->addDefinitions(array_replace_recursive(...$dependenciesCollection));
|
||||
return $builder->build();
|
||||
} catch (Exception $e) {echo $e->getMessage();}
|
||||
2
config/components/loggerFactory.php
Normal file
2
config/components/loggerFactory.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
return (new \Monolog\Logger('system'))->pushHandler(new \Monolog\Handler\StreamHandler(dirname(__DIR__, 2).'/var/logs/log'.date('Ymd').'.log'));
|
||||
2
config/components/routerFactory.php
Normal file
2
config/components/routerFactory.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
return new \Rmphp\Router\Router();
|
||||
4
config/components/templateFactory.php
Normal file
4
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
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"), true)),
|
||||
'App\Domain\Repository\*RepositoryInterface' => DI\autowire('App\Infrastructure\Repository\*Repository'),
|
||||
'App\*\Domain\Repository\*RepositoryInterface' => DI\autowire('App\*\Infrastructure\Repository\*Repository'),
|
||||
];
|
||||
5
config/container/settings.php
Normal file
5
config/container/settings.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
//"container key"=>value
|
||||
];
|
||||
13
config/routes/99-main.yaml
Normal file
13
config/routes/99-main.yaml
Normal file
@@ -0,0 +1,13 @@
|
||||
# Index
|
||||
- key: "/"
|
||||
routes:
|
||||
- action: "App\\Infrastructure\\Controllers\\IndexController"
|
||||
method: "index"
|
||||
params: ""
|
||||
|
||||
# Empty
|
||||
- key: "<@any>"
|
||||
routes:
|
||||
- action: "App\\Infrastructure\\Controllers\\IndexController"
|
||||
method: "emptyAction"
|
||||
params: ""
|
||||
16
config/routes/routes.php
Normal file
16
config/routes/routes.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
$cashFile = preg_replace("'.config.*$'",'', __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;
|
||||
}
|
||||
Reference in New Issue
Block a user