|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Tests\Support; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Container\ContainerInterface; |
|
8
|
|
|
use Yiisoft\Config\Config; |
|
9
|
|
|
use Yiisoft\Yii\Runner\Console\ConsoleApplicationRunner; |
|
10
|
|
|
use Yiisoft\Yii\Runner\Http\HttpApplicationRunner; |
|
11
|
|
|
|
|
12
|
|
|
final class ApplicationDataProvider |
|
13
|
|
|
{ |
|
14
|
|
|
private static ?ConsoleApplicationRunner $consoleRunner = null; |
|
15
|
|
|
private static ?HttpApplicationRunner $webRunner = null; |
|
16
|
|
|
|
|
17
|
|
|
public static function getConsoleConfig(): Config |
|
18
|
|
|
{ |
|
19
|
|
|
return self::getConsoleRunner()->getConfig(); |
|
|
|
|
|
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public static function getConsoleContainer(): ContainerInterface |
|
23
|
|
|
{ |
|
24
|
|
|
return self::getConsoleRunner()->getContainer(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public static function getWebConfig(): Config |
|
28
|
|
|
{ |
|
29
|
|
|
return self::getConsoleRunner()->getConfig(); |
|
|
|
|
|
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public static function getWebContainer(): ContainerInterface |
|
33
|
|
|
{ |
|
34
|
|
|
return self::getConsoleRunner()->getContainer(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
private static function getConsoleRunner(): ConsoleApplicationRunner |
|
38
|
|
|
{ |
|
39
|
|
|
if (self::$consoleRunner === null) { |
|
40
|
|
|
self::$consoleRunner = new ConsoleApplicationRunner( |
|
41
|
|
|
rootPath: dirname(__DIR__, 2), |
|
42
|
|
|
environment: $_ENV['YII_ENV'] |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
return self::$consoleRunner; |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
private static function getWebRunner(): HttpApplicationRunner |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
if (self::$webRunner === null) { |
|
51
|
|
|
self::$webRunner = new HttpApplicationRunner( |
|
52
|
|
|
rootPath: dirname(__DIR__, 2), |
|
53
|
|
|
environment: $_ENV['YII_ENV'] |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
return self::$webRunner; |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|