Skip to content

Commit

Permalink
changed to controllerMap removed config component
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Apr 26, 2017
1 parent c2c2574 commit 3b2dee9
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 126 deletions.
71 changes: 37 additions & 34 deletions src/base/Starter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,11 +33,6 @@ class Starter
*/
private $_rootDir;

/**
* @var bool hidev already started flag
*/
public static $started = false;

/**
* @var array goals definitions
*/
Expand All @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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)) {
Expand All @@ -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]);
Expand Down Expand Up @@ -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;
}
}
}

Expand Down
9 changes: 0 additions & 9 deletions src/base/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
154 changes: 74 additions & 80 deletions src/config/basis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 => [
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/DumpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 3b2dee9

Please sign in to comment.