1 | <?php |
||
16 | class Context |
||
17 | { |
||
18 | /** |
||
19 | * @var Host |
||
20 | */ |
||
21 | private $host; |
||
22 | |||
23 | /** |
||
24 | * @var InputInterface |
||
25 | */ |
||
26 | private $input; |
||
27 | |||
28 | /** |
||
29 | * @var OutputInterface |
||
30 | */ |
||
31 | private $output; |
||
32 | |||
33 | /** |
||
34 | * @var Context[] |
||
35 | */ |
||
36 | private static $contexts = []; |
||
37 | |||
38 | /** |
||
39 | * @param Host $host |
||
40 | * @param InputInterface $input |
||
41 | * @param OutputInterface $output |
||
42 | */ |
||
43 | 19 | public function __construct($host, InputInterface $input = null, OutputInterface $output = null) |
|
49 | |||
50 | /** |
||
51 | * @param Context $context |
||
52 | */ |
||
53 | 21 | public static function push(Context $context) |
|
57 | |||
58 | /** |
||
59 | * @return bool |
||
60 | */ |
||
61 | 14 | public static function has() |
|
65 | |||
66 | /** |
||
67 | * @return Context|false |
||
68 | * @throws Exception |
||
69 | */ |
||
70 | 14 | public static function get() |
|
77 | |||
78 | /** |
||
79 | * @return Context |
||
80 | */ |
||
81 | 21 | public static function pop() |
|
85 | |||
86 | /** |
||
87 | * Throws a Exception when not called within a task-context and therefore no Context is available. |
||
88 | * |
||
89 | * This method provides a useful error to the end-user to make him/her aware |
||
90 | * to use a function in the required task-context. |
||
91 | * |
||
92 | * @param string $callerName |
||
93 | * @throws Exception |
||
94 | */ |
||
95 | 1 | public static function required($callerName) |
|
96 | { |
||
97 | 1 | if (empty(self::$contexts)) { |
|
98 | throw new Exception("'$callerName' can only be used within a task."); |
||
99 | } |
||
100 | 1 | } |
|
101 | |||
102 | /** |
||
103 | * @return Configuration |
||
104 | */ |
||
105 | 13 | public function getConfig() |
|
109 | |||
110 | /** |
||
111 | * @return InputInterface |
||
112 | */ |
||
113 | 6 | public function getInput() |
|
117 | |||
118 | /** |
||
119 | * @return OutputInterface |
||
120 | */ |
||
121 | 10 | public function getOutput() |
|
125 | |||
126 | /** |
||
127 | * @return Host |
||
128 | */ |
||
129 | 12 | public function getHost() |
|
133 | } |
||
134 |