diff --git a/src/base/Starter.php b/src/base/Starter.php index 5c1f0aa..90f8cff 100644 --- a/src/base/Starter.php +++ b/src/base/Starter.php @@ -23,7 +23,7 @@ * Chdirs to the project's root directory and loads dependencies and configs. * * XXX it's important to distinguish: - * - goals definitions + * - goals definitions (hidev config) * - application config */ class Starter @@ -33,11 +33,6 @@ class Starter */ private $_rootDir; - /** - * @var bool hidev already started flag - */ - public static $started = false; - /** * @var array goals definitions */ @@ -55,17 +50,25 @@ class Starter */ public function __construct() { - self::$started = true; $this->getRootDir(); - $this->loadConfig(); + $this->loadGoals(); $this->addAliases(); // $this->addAutoloader(); $this->requireAll(); $this->includeAll(); - $this->moreAppConfig(); + $this->moreConfig(); } public function getConfig() + { + $config = ArrayHelper::merge($this->readConfig(), [ + 'controllerMap' => $this->goals, + ]); + + return $config; + } + + public function readConfig() { $config = []; foreach ($this->appFiles as $file) { @@ -81,20 +84,22 @@ public function getGoals() return $this->goals; } - private function loadConfig() + private function loadGoals() { - $this->includeConfig('hidev.yml'); + $this->includeGoals('hidev.yml'); if (file_exists('hidev-local.yml')) { - $this->includeConfig('hidev-local.yml'); + $this->includeGoals('hidev-local.yml'); } } - private function includeConfig($path) + private function includeGoals($paths) { - $this->config = ArrayHelper::merge( - $this->config, - $this->readYaml($path) - ); + foreach ((array)$paths as $path) { + $this->goals = ArrayHelper::merge( + $this->goals, + $this->readYaml($path) + ); + } } private function readYaml($path) @@ -123,13 +128,13 @@ private function addAliases() { Yii::setAlias('@root', $this->getRootDir()); Yii::setAlias('@hidev', dirname(__DIR__)); - $package = $this->config['package']; + $package = $this->goals['package']; $alias = isset($package['namespace']) ? strtr($package['namespace'], '\\', '/') : ''; if ($alias && !Yii::getAlias('@' . $alias, false)) { $srcdir = Yii::getAlias('@root/' . ($package['src'] ?: 'src')); Yii::setAlias($alias, $srcdir); } - $aliases = $this->config['aliases']; + $aliases = $this->goals['aliases']; if (!empty($aliases) && is_array($aliases)) { foreach ($aliases as $alias => $path) { if (!$this->hasAlias($alias)) { @@ -153,7 +158,7 @@ private function hasAlias($alias, $exact = true) */ private function requireAll() { - $plugins = $this->config['plugins']; + $plugins = $this->goals['plugins']; if ($plugins) { $file = File::create('.hidev/composer.json'); $data = ArrayHelper::merge($file->load(), ['require' => $plugins]); @@ -232,26 +237,24 @@ private function needsComposerInstall() */ private function includeAll() { - $still = true; - while ($still) { - $still = false; - $include = $this->config['include']; - if ($include) { - foreach ($include as $path) { - $still = $still || $this->includeConfig($path); - } - } - } + $config = $this->readConfig(); + $files = array_merge( + (array)$this->goals['include'], + (array)$config['controllerMap']['include'] + ); + $this->includeGoals($files); } /** * Registers more application config to load. */ - private function moreAppConfig() + private function moreConfig() { - $path = $this->config['config']; - if ($path) { - $this->appFiles[] = $path; + $paths = $this->goals['config']; + foreach ((array)$paths as $path) { + if ($path) { + $this->appFiles[] = $path; + } } } diff --git a/src/base/View.php b/src/base/View.php index 7ff4361..10a5f97 100644 --- a/src/base/View.php +++ b/src/base/View.php @@ -22,15 +22,6 @@ class View extends \yii\base\View */ public $defaultExtension = 'twig'; - public function init() - { - parent::init(); - $this->theme->pathMap['@app/views'] = array_merge( - (array) $this->theme->pathMap['@app/views'], - (array) Yii::$app->get('config')->rawItem('views') - ); - } - public function getConfig() { return Yii::$app->config; diff --git a/src/config/basis.php b/src/config/basis.php index 93ac7b5..ffcc794 100644 --- a/src/config/basis.php +++ b/src/config/basis.php @@ -32,93 +32,16 @@ ], ], 'cache' => [ - 'class' => 'yii\caching\FileCache', + 'class' => \yii\caching\FileCache::class, ], /*'request' => [ 'class' => 'hidev\base\Request', ],*/ - 'config' => [ - 'class' => 'hidev\components\Config', - /// internally used actions - 'binaries' => [ - 'class' => 'hidev\controllers\BinariesController', - 'composer' => [ - 'class' => 'hidev\base\BinaryPhp', - 'installer' => 'https://getcomposer.org/installer', - ], - 'pip' => [ - 'class' => 'hidev\base\BinaryPython', - 'installer' => 'https://bootstrap.pypa.io/get-pip.py', - ], - ], - /// basic actions - 'init' => [ - 'class' => 'hidev\controllers\InitController', - ], - '--version' => [ - 'class' => 'hidev\controllers\OwnVersionController', - ], - 'update' => [ - 'before' => [ - 'start/update', - ], - ], - /// standard actions - 'vendor' => [ - 'class' => 'hidev\controllers\VendorController', - ], - 'package' => [ - 'class' => 'hidev\controllers\PackageController', - ], - 'command' => [ - 'class' => 'hidev\controllers\CommandController', - ], - 'template' => [ - 'class' => 'hidev\controllers\TemplateController', - ], - 'directory' => [ - 'class' => 'hidev\controllers\DirectoryController', - ], - /// git/vcs actions - 'github' => [ - 'class' => 'hidev\controllers\GithubController', - ], - 'vcsignore' => [ - 'class' => 'hidev\controllers\VcsignoreController', - ], - '.gitignore' => [ - 'class' => 'hidev\controllers\GitignoreController', - ], - /// Yii built-in controllers - 'asset' => [ - 'class' => 'yii\console\controllers\AssetController', - ], - 'cache' => [ - 'class' => 'yii\console\controllers\CacheController', - ], - 'fixture' => [ - 'class' => 'yii\console\controllers\FixtureController', - ], - 'message' => [ - 'class' => 'yii\console\controllers\MessageController', - ], - 'migrate' => [ - 'class' => 'yii\console\controllers\MigrateController', - ], - 'serve' => [ - 'class' => 'yii\console\controllers\ServeController', - ], - ], 'view' => [ - 'class' => 'hidev\base\View', - 'theme' => [ - 'pathMap' => [ - '@app/views' => ['@hidev/views'], - ], - ], + 'class' => \hidev\base\View::class, 'renderers' => [ 'twig' => [ - 'class' => 'yii\twig\ViewRenderer', + 'class' => \yii\twig\ViewRenderer::class, 'cachePath' => '@runtime/Twig/cache', 'options' => [ 'auto_reload' => true, @@ -128,6 +51,77 @@ ], ], ], + 'controllerMap' => [ + /// internally used actions + 'binaries' => [ + 'class' => \hidev\controllers\BinariesController::class, + 'composer' => [ + 'class' => \hidev\base\BinaryPhp::class, + 'installer' => 'https://getcomposer.org/installer', + ], + 'pip' => [ + 'class' => \hidev\base\BinaryPython::class, + 'installer' => 'https://bootstrap.pypa.io/get-pip.py', + ], + ], + /// basic actions + 'init' => [ + 'class' => 'hidev\controllers\InitController', + ], + '--version' => [ + 'class' => 'hidev\controllers\OwnVersionController', + ], + 'update' => [ + 'before' => [ + 'start/update', + ], + ], + /// standard actions + 'vendor' => [ + 'class' => 'hidev\controllers\VendorController', + ], + 'package' => [ + 'class' => 'hidev\controllers\PackageController', + ], + 'command' => [ + 'class' => 'hidev\controllers\CommandController', + ], + 'template' => [ + 'class' => 'hidev\controllers\TemplateController', + ], + 'directory' => [ + 'class' => 'hidev\controllers\DirectoryController', + ], + /// git/vcs actions + 'github' => [ + 'class' => 'hidev\controllers\GithubController', + ], + 'vcsignore' => [ + 'class' => 'hidev\controllers\VcsignoreController', + ], + '.gitignore' => [ + 'class' => 'hidev\controllers\GitignoreController', + ], + /// Yii built-in controllers + 'asset' => [ + 'class' => 'yii\console\controllers\AssetController', + ], + 'cache' => [ + 'class' => 'yii\console\controllers\CacheController', + ], + 'fixture' => [ + 'class' => 'yii\console\controllers\FixtureController', + ], + 'message' => [ + 'class' => 'yii\console\controllers\MessageController', + ], + 'migrate' => [ + 'class' => 'yii\console\controllers\MigrateController', + ], + 'serve' => [ + 'class' => 'yii\console\controllers\ServeController', + ], + ], 'container' => [ 'singletons' => [ \hidev\components\Interpolator::class => [ diff --git a/src/controllers/DumpController.php b/src/controllers/DumpController.php index 3784f12..945ad13 100644 --- a/src/controllers/DumpController.php +++ b/src/controllers/DumpController.php @@ -21,15 +21,15 @@ class DumpController extends CommonController { public function actionMake() { - $data = $this->takeConfig()->getItems(); - unset($data['dump'], $data['start']); + $data = Yii::$app->controllerMap; echo Yaml::dump(ArrayHelper::toArray($data), 4); } public function actionInternals() { $internals = [ - 'aliases' => Yii::$aliases, + 'aliases' => Yii::$aliases, + 'view.theme.pathMap' => Yii::$app->view->theme->pathMap, ]; echo Yaml::dump($internals, 4); }