mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Восстановлен запуск тестов
Загрузчик конфигов выделен в отдельный класс authserverHost выделена в params Исправлены некоторые common.unit тесты, т.к. наследовались не от того базового класса
This commit is contained in:
2
common/config/.gitignore
vendored
2
common/config/.gitignore
vendored
@@ -1 +1 @@
|
||||
main-local.php
|
||||
config-local.php
|
||||
|
65
common/config/ConfigLoader.php
Normal file
65
common/config/ConfigLoader.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace common\config;
|
||||
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class ConfigLoader {
|
||||
|
||||
/*
|
||||
* TODO: В PHP 7.1 следует сделать её protected
|
||||
*/
|
||||
const ROOT_PATH = __DIR__ . '/../..';
|
||||
|
||||
private $application;
|
||||
|
||||
public function __construct(string $application) {
|
||||
$this->application = $application;
|
||||
}
|
||||
|
||||
public function getEnvironment() : string {
|
||||
return YII_ENV;
|
||||
}
|
||||
|
||||
public function getConfig() : array {
|
||||
$toMerge = [
|
||||
require __DIR__ . '/config.php',
|
||||
];
|
||||
|
||||
// Общие окружение-зависимые настройки
|
||||
$path = __DIR__ . '/config-' . YII_ENV . '.php';
|
||||
if (file_exists($path)) {
|
||||
$toMerge[] = require $path;
|
||||
}
|
||||
|
||||
// Общие локальные настройки
|
||||
$path = __DIR__ . '/config-local.php';
|
||||
if (file_exists($path)) {
|
||||
$toMerge[] = require $path;
|
||||
}
|
||||
|
||||
// Настройки конкретного приложения
|
||||
$path = self::ROOT_PATH . '/' . $this->application . '/config/config.php';
|
||||
if (file_exists($path)) {
|
||||
$toMerge[] = require $path;
|
||||
}
|
||||
|
||||
// Настройки конкретного приложения для действующего окружения
|
||||
$path = self::ROOT_PATH . '/' . $this->application . '/config/main-' . YII_ENV . '.php';
|
||||
if (file_exists($path)) {
|
||||
$toMerge[] = require $path;
|
||||
}
|
||||
|
||||
// Локальные настройки конкретного приложения
|
||||
$path = self::ROOT_PATH . '/' . $this->application . '/config/config-local.php';
|
||||
if (file_exists($path)) {
|
||||
$toMerge[] = require $path;
|
||||
}
|
||||
|
||||
return ArrayHelper::merge(...$toMerge);
|
||||
}
|
||||
|
||||
public static function load(string $application) : array {
|
||||
return (new static($application))->getConfig();
|
||||
}
|
||||
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
$rootPath = __DIR__ . '/../..';
|
||||
|
||||
$toMerge = [
|
||||
require __DIR__ . '/main.php',
|
||||
];
|
||||
|
||||
// Общие окружение-зависимые настройки
|
||||
$path = __DIR__ . '/common-' . YII_ENV . '.php';
|
||||
if (file_exists($path)) {
|
||||
$toMerge[] = require $path;
|
||||
}
|
||||
|
||||
// Общие локальные настройки
|
||||
$path = __DIR__ . '/common-local.php';
|
||||
if (file_exists($path)) {
|
||||
$toMerge[] = require $path;
|
||||
}
|
||||
|
||||
// Настройки конкретного приложения
|
||||
$path = $rootPath . '/' . YII_APPLICATION_MODULE . '/config/main.php';
|
||||
if (file_exists($path)) {
|
||||
$toMerge[] = require $path;
|
||||
}
|
||||
|
||||
// Настройки конкретного приложения для действующего окружения
|
||||
$path = $rootPath . '/' . YII_APPLICATION_MODULE . '/config/main-' . YII_ENV . '.php';
|
||||
if (file_exists($path)) {
|
||||
$toMerge[] = require $path;
|
||||
}
|
||||
|
||||
// Локальные настройки конкретного приложения
|
||||
$path = $rootPath . '/' . YII_APPLICATION_MODULE . '/config/main-local.php';
|
||||
if (file_exists($path)) {
|
||||
$toMerge[] = require $path;
|
||||
}
|
||||
|
||||
// не оставляем глобальных переменных, ну кроме $toMerge, хех
|
||||
unset($path, $rootPath);
|
||||
|
||||
return ArrayHelper::merge(...$toMerge);
|
Reference in New Issue
Block a user