20241102#1
This commit is contained in:
13
application/config/app.php
Normal file
13
application/config/app.php
Normal 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'],
|
||||
];
|
||||
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',
|
||||
];
|
||||
19
application/config/components/containerFactory.php
Normal file
19
application/config/components/containerFactory.php
Normal 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();}
|
||||
2
application/config/components/loggerFactory.php
Normal file
2
application/config/components/loggerFactory.php
Normal 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'));
|
||||
2
application/config/components/routerFactory.php
Normal file
2
application/config/components/routerFactory.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
return new \Rmphp\Router\Router();
|
||||
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/templates",
|
||||
]);
|
||||
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",
|
||||
];
|
||||
15
application/config/container/services.php
Normal file
15
application/config/container/services.php
Normal 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'),
|
||||
];
|
||||
5
application/config/container/settings.php
Normal file
5
application/config/container/settings.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
//"container key"=>value
|
||||
];
|
||||
13
application/config/routes/99-main.yaml
Normal file
13
application/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\\nfrastructure\\Controllers\\IndexController"
|
||||
method: "emptyAction"
|
||||
params: ""
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user