1 | <?php declare(strict_types=1); |
||
2 | /** |
||
3 | * @author Vitaliy IIIFX Khomenko (c) 2021 |
||
4 | * @license MIT |
||
5 | * |
||
6 | * @link https://github.com/iiifx-production/yii2-autocomplete-helper |
||
7 | */ |
||
8 | |||
9 | namespace iiifx\Yii2\Autocomplete; |
||
10 | |||
11 | use yii\base\Application; |
||
12 | use yii\base\BaseObject; |
||
13 | use yii\base\BootstrapInterface; |
||
14 | |||
15 | class Component extends BaseObject implements BootstrapInterface |
||
16 | { |
||
17 | public string $environment = 'dev'; |
||
18 | public array $controllerMap = [ |
||
19 | 'ide-components' => Controller::class, |
||
20 | ]; |
||
21 | public ?string $result = null; |
||
22 | public ?array $config = null; |
||
23 | public ?string $webAppClass = null; |
||
24 | public ?string $consoleAppClass = null; |
||
25 | |||
26 | /** |
||
27 | * @inheritdoc |
||
28 | */ |
||
29 | public function bootstrap($app) |
||
30 | { |
||
31 | if ($app instanceof \yii\console\Application && $this->isActive()) { |
||
32 | $this->updateControllerMap($app); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | public function isActive(): bool |
||
37 | { |
||
38 | return defined('YII_ENV') && YII_ENV === $this->environment; |
||
39 | } |
||
40 | |||
41 | protected function updateControllerMap(Application $app): void |
||
42 | { |
||
43 | if (is_array($this->controllerMap)) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
44 | foreach ($this->controllerMap as $name => $controller) { |
||
45 | if (is_subclass_of($controller, \yii\console\Controller::class)) { |
||
46 | $app->controllerMap[$name] = $controller; |
||
47 | } |
||
48 | } |
||
49 | } |
||
50 | } |
||
51 | } |
||
52 |