|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Automation tool mixed with code generator for easier continuous development. |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/hiqdev/hidev |
|
6
|
|
|
* @package hidev |
|
7
|
|
|
* @license BSD-3-Clause |
|
8
|
|
|
* @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace hidev\console; |
|
12
|
|
|
|
|
13
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
14
|
|
|
use Yii; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Dump available definitions: components, controllers, aliases. |
|
18
|
|
|
*/ |
|
19
|
|
|
class DumpController extends \yii\console\Controller |
|
20
|
|
|
{ |
|
21
|
|
|
public $defaultAction = 'component'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Dump defined components. |
|
25
|
|
|
* @param string $name component name |
|
26
|
|
|
*/ |
|
27
|
|
View Code Duplication |
public function actionComponent($name = null) |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
$data = Yii::$app->getComponents(); |
|
30
|
|
|
if ($name) { |
|
|
|
|
|
|
31
|
|
|
if (empty($data[$name])) { |
|
32
|
|
|
Yii::error("'$name' not defined"); |
|
33
|
|
|
return; |
|
34
|
|
|
} |
|
35
|
|
|
$data = [$name => $data[$name]]; |
|
36
|
|
|
} |
|
37
|
|
|
echo Yaml::dump($data, 4); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Dump defined controllers. |
|
42
|
|
|
* @param string $name controller name |
|
43
|
|
|
*/ |
|
44
|
|
View Code Duplication |
public function actionController($name = null) |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
$data = Yii::$app->controllerMap; |
|
47
|
|
|
if ($name) { |
|
|
|
|
|
|
48
|
|
|
if (empty($data[$name])) { |
|
49
|
|
|
Yii::error("'$name' not defined"); |
|
50
|
|
|
return; |
|
51
|
|
|
} |
|
52
|
|
|
$data = [$name => $data[$name]]; |
|
53
|
|
|
} |
|
54
|
|
|
echo Yaml::dump($data, 4); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Dump defined aliases. |
|
59
|
|
|
* @param string $alias alias to resolve |
|
60
|
|
|
*/ |
|
61
|
|
|
public function actionAlias($alias = null) |
|
62
|
|
|
{ |
|
63
|
|
|
$data = Yii::$aliases; |
|
64
|
|
|
if ($alias) { |
|
|
|
|
|
|
65
|
|
|
$dest = Yii::getAlias($alias, false); |
|
66
|
|
|
if (empty($dest)) { |
|
67
|
|
|
Yii::error("'$alias' not defined"); |
|
68
|
|
|
return; |
|
69
|
|
|
} |
|
70
|
|
|
$data = [$alias => $dest]; |
|
71
|
|
|
} |
|
72
|
|
|
echo Yaml::dump($data, 4); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.