1 | <?php |
||
16 | class Context |
||
17 | { |
||
18 | /** |
||
19 | * @var ServerInterface|null |
||
20 | */ |
||
21 | private $server; |
||
22 | |||
23 | /** |
||
24 | * @var Environment|null |
||
25 | */ |
||
26 | private $env; |
||
27 | |||
28 | /** |
||
29 | * @var InputInterface|null |
||
30 | */ |
||
31 | private $input; |
||
32 | |||
33 | /** |
||
34 | * @var OutputInterface|null |
||
35 | */ |
||
36 | private $output; |
||
37 | |||
38 | /** |
||
39 | * @var Context[] |
||
40 | */ |
||
41 | private static $contexts = []; |
||
42 | |||
43 | /** |
||
44 | * @param ServerInterface|null $server |
||
45 | * @param Environment|null $env |
||
46 | * @param InputInterface|null $input |
||
47 | * @param OutputInterface|null $output |
||
48 | */ |
||
49 | 25 | public function __construct($server, $env, $input, $output) |
|
56 | |||
57 | /** |
||
58 | * @param Context $context |
||
59 | */ |
||
60 | 28 | public static function push(Context $context) |
|
64 | |||
65 | /** |
||
66 | * @return Context|false |
||
67 | */ |
||
68 | 24 | public static function get() |
|
72 | |||
73 | /** |
||
74 | * Returns the current context when available. |
||
75 | * |
||
76 | * Throws a Exception when not called within a task-context and therefore no Context is available. |
||
77 | * |
||
78 | * This method provides a usefull error to the end-user to make him/her aware |
||
79 | * to use a function in the required task-context. |
||
80 | * |
||
81 | * @throws Exception |
||
82 | */ |
||
83 | public static function required($callerName) |
||
89 | |||
90 | /** |
||
91 | * @return Context |
||
92 | */ |
||
93 | 28 | public static function pop() |
|
97 | |||
98 | /** |
||
99 | * @return Environment|null |
||
100 | */ |
||
101 | 20 | public function getEnvironment() |
|
105 | |||
106 | /** |
||
107 | * @return InputInterface|null |
||
108 | */ |
||
109 | 1 | public function getInput() |
|
113 | |||
114 | /** |
||
115 | * @return OutputInterface|null |
||
116 | */ |
||
117 | 17 | public function getOutput() |
|
121 | |||
122 | /** |
||
123 | * @return ServerInterface|null |
||
124 | */ |
||
125 | 13 | public function getServer() |
|
129 | } |
||
130 |