hiqdev /
hidev
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * Task runner, code generator and build tool for easier continuos integration |
||
| 5 | * |
||
| 6 | * @link https://github.com/hiqdev/hidev |
||
| 7 | * @package hidev |
||
| 8 | * @license BSD-3-Clause |
||
| 9 | * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/) |
||
| 10 | */ |
||
| 11 | |||
| 12 | namespace hidev\controllers; |
||
| 13 | |||
| 14 | use hidev\base\Application; |
||
| 15 | use hidev\base\File; |
||
| 16 | use Yii; |
||
| 17 | use yii\base\InvalidConfigException; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Start goal. |
||
| 21 | * Chdirs to the project's root directory and loads dependencies and configs. |
||
| 22 | */ |
||
| 23 | class StartController extends CommonController |
||
| 24 | { |
||
| 25 | const MAIN_CONFIG = '.hidev/config.yml'; |
||
| 26 | |||
| 27 | static $started = false; |
||
|
0 ignored issues
–
show
|
|||
| 28 | |||
| 29 | public function actionMake() |
||
| 30 | { |
||
| 31 | Yii::setAlias('@prjdir', $this->findDir()); |
||
| 32 | $this->takeConfig()->includeConfig(static::MAIN_CONFIG); |
||
| 33 | $this->requireAll(); |
||
| 34 | $this->includeAll(); |
||
| 35 | self::$started = true; |
||
| 36 | } |
||
| 37 | |||
| 38 | protected function requireAll() |
||
| 39 | { |
||
| 40 | $require = $this->takeConfig()->rawItem('require'); |
||
| 41 | if ($require) { |
||
| 42 | $require['hiqdev/composer-extension-plugin'] = '*@dev'; |
||
| 43 | $saved = File::create('.hidev/composer.json')->save(compact('require')); |
||
| 44 | if ($saved || !is_dir('.hidev/vendor')) { |
||
| 45 | $this->takeGoal('update')->makeUpdate(); |
||
| 46 | } |
||
| 47 | /// backup config then reset with extra config then restore |
||
| 48 | $config = $this->takeConfig()->getItems(); |
||
| 49 | Yii::$app->clear('config'); |
||
| 50 | Yii::$app->loadExtraVendor('.hidev/vendor'); |
||
| 51 | $this->takeConfig()->mergeItems($config); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Include all configs. |
||
| 57 | * @return void |
||
| 58 | */ |
||
| 59 | public function includeAll() |
||
| 60 | { |
||
| 61 | $still = true; |
||
| 62 | while ($still) { |
||
| 63 | $still = false; |
||
| 64 | $include = $this->takeConfig()->rawItem('include'); |
||
| 65 | if ($include) { |
||
| 66 | foreach ($include as $path) { |
||
| 67 | $still = $still || $this->takeConfig()->includeConfig($path); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Chdirs to project's root by looking for config file in the current directory and up. |
||
| 75 | * @return string path to the root directory of hidev project |
||
| 76 | * @throws InvalidConfigException when failed to find |
||
| 77 | */ |
||
| 78 | protected function findDir() |
||
| 79 | { |
||
| 80 | $configDir = '.hidev'; |
||
| 81 | for ($i = 0;$i < 9;++$i) { |
||
| 82 | if (is_dir($configDir)) { |
||
| 83 | return getcwd(); |
||
| 84 | } |
||
| 85 | chdir('..'); |
||
| 86 | } |
||
| 87 | throw new InvalidConfigException('Not a hidev project (or any of the parent directories). Use `hidev init` to initialize hidev project.'); |
||
| 88 | } |
||
| 89 | } |
||
| 90 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.