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) 2015-2016, HiQDev (http://hiqdev.com/) |
||
| 10 | */ |
||
| 11 | |||
| 12 | namespace hidev\base; |
||
| 13 | |||
| 14 | use Exception; |
||
| 15 | use Yii; |
||
| 16 | use yii\base\InvalidParamException; |
||
| 17 | use yii\base\ViewContextInterface; |
||
| 18 | use yii\console\Exception as ConsoleException; |
||
| 19 | use yii\helpers\ArrayHelper; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * The Application. |
||
| 23 | */ |
||
| 24 | class Application extends \yii\console\Application implements ViewContextInterface |
||
| 25 | { |
||
| 26 | protected $_viewPath; |
||
| 27 | |||
| 28 | protected $_config; |
||
| 29 | |||
| 30 | protected $_first = true; |
||
| 31 | |||
| 32 | public function __construct($config = []) |
||
| 33 | { |
||
| 34 | $this->_config = $config; |
||
| 35 | parent::__construct($config); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Creates application with given config and runs it. |
||
| 40 | * @param array $config |
||
| 41 | * @return int exit code |
||
| 42 | */ |
||
| 43 | public static function main(array $config) |
||
| 44 | { |
||
| 45 | try { |
||
| 46 | Yii::setLogger(Yii::createObject('hidev\base\Logger')); |
||
| 47 | $config = ArrayHelper::merge( |
||
| 48 | static::readExtraVendor($config['vendorPath']), |
||
| 49 | $config |
||
| 50 | ); |
||
| 51 | $exitCode = (new static($config))->run(); |
||
| 52 | } catch (Exception $e) { |
||
| 53 | if ($e instanceof InvalidParamException || $e instanceof ConsoleException) { |
||
| 54 | Yii::error($e->getMessage()); |
||
| 55 | $exitCode = 1; |
||
| 56 | } else { |
||
| 57 | throw $e; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | return $exitCode; |
||
| 62 | } |
||
| 63 | |||
| 64 | public static function readExtraVendor($dir) |
||
| 65 | { |
||
| 66 | return require $dir . '/yiisoft/yii2-extraconfig.php'; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Load extra config files. |
||
| 71 | * @param array $config |
||
| 72 | * @return void |
||
| 73 | */ |
||
| 74 | public function loadExtraVendor($dir) |
||
| 75 | { |
||
| 76 | $this->setExtraConfig(static::readExtraVendor($dir)); |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Implements extra configuration. |
||
| 81 | * @param array $config |
||
| 82 | * @return void |
||
| 83 | */ |
||
| 84 | public function setExtraConfig($config) |
||
| 85 | { |
||
| 86 | $this->_config = $config = ArrayHelper::merge($config, $this->_config); |
||
| 87 | |||
| 88 | if (!empty($config['aliases'])) { |
||
| 89 | $this->setAliases($config['aliases']); |
||
| 90 | } |
||
| 91 | if (!empty($config['modules'])) { |
||
| 92 | $this->setModules($config['modules']); |
||
| 93 | /*$this->setModules(ArrayHelper::merge( |
||
|
0 ignored issues
–
show
|
|||
| 94 | $config['modules'], |
||
| 95 | ArrayHelper::getItems($this->modules, array_keys($config['modules'])) |
||
| 96 | ));*/ |
||
| 97 | } |
||
| 98 | if (!empty($config['components'])) { |
||
| 99 | foreach ($config['components'] as $id => $component) { |
||
| 100 | if ($this->has($id, true)) { |
||
| 101 | unset($config['components'][$id]); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | $this->setComponents($config['components']); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | /*public function getViewPath() |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
52% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 109 | { |
||
| 110 | if ($this->_viewPath === null) { |
||
| 111 | $this->_viewPath = Yii::getAlias('@app/views'); |
||
| 112 | } |
||
| 113 | |||
| 114 | return $this->_viewPath; |
||
| 115 | }*/ |
||
| 116 | |||
| 117 | public function createControllerByID($id) |
||
| 118 | { |
||
| 119 | /// skip start for init goal |
||
| 120 | if ($this->_first) { |
||
| 121 | $this->_first = false; |
||
| 122 | static $skips = ['init' => 1, 'clone' => 1, '--version' => 1]; |
||
| 123 | if (!$skips[$id]) { |
||
| 124 | $this->runRequest('start'); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | if ($this->get('config')->hasGoal($id)) { |
||
| 129 | return $this->get('config')->get($id); |
||
| 130 | } |
||
| 131 | |||
| 132 | $controller = parent::createControllerByID($id); |
||
| 133 | $this->get('config')->set($id, $controller); |
||
| 134 | |||
| 135 | return $controller; |
||
| 136 | } |
||
| 137 | |||
| 138 | public function runRequest($string) |
||
| 139 | { |
||
| 140 | $request = Yii::createObject([ |
||
| 141 | 'class' => 'hidev\base\Request', |
||
| 142 | 'params' => array_filter(explode(' ', $string)), |
||
| 143 | ]); |
||
| 144 | |||
| 145 | return $this->handleRequest($request); |
||
| 146 | } |
||
| 147 | } |
||
| 148 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.