-
Notifications
You must be signed in to change notification settings - Fork 16
/
GlobalHelper.php
98 lines (80 loc) 路 2.59 KB
/
GlobalHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace Castor;
use Castor\Console\Application;
use Castor\Console\Output\SectionOutput;
use Monolog\Logger;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class GlobalHelper
{
private static Application $application;
public static function setApplication(Application $application): void
{
self::$application = $application;
}
public static function getApplication(): Application
{
return self::$application ?? throw new \LogicException('Application not available yet.');
}
public static function getContextRegistry(): ContextRegistry
{
return self::getApplication()->contextRegistry;
}
public static function getEventDispatcher(): EventDispatcher
{
return self::getApplication()->eventDispatcher;
}
public static function getFilesystem(): Filesystem
{
return self::getApplication()->fs;
}
public static function getHttpClient(): HttpClientInterface
{
return self::getApplication()->httpClient;
}
public static function getCache(): CacheItemPoolInterface&CacheInterface
{
return self::getApplication()->cache;
}
public static function getLogger(): Logger
{
return self::getApplication()->logger;
}
public static function getInput(): InputInterface
{
return self::getApplication()->getInput();
}
public static function getSectionOutput(): SectionOutput
{
return self::getApplication()->getSectionOutput();
}
public static function getOutput(): OutputInterface
{
return self::getApplication()->getOutput();
}
public static function getSymfonyStyle(): SymfonyStyle
{
return self::getApplication()->getSymfonyStyle();
}
/**
* @return ($allowNull is true ? ?Command : Command)
*/
public static function getCommand(bool $allowNull = false): ?Command
{
return self::getApplication()->getCommand($allowNull);
}
public static function getContext(?string $name = null): Context
{
return self::getContextRegistry()->get($name);
}
public static function getVariable(string $key, mixed $default = null): mixed
{
return self::getContextRegistry()->getVariable($key, $default);
}
}