1 | <?php |
||
32 | class ConsoleResponse extends Response |
||
33 | { |
||
34 | /** |
||
35 | * @var string The content to send back with this response. |
||
36 | */ |
||
37 | protected $content = ''; |
||
38 | |||
39 | /** |
||
40 | * @var int The shell exit code. |
||
41 | */ |
||
42 | protected $exitCode = 0; |
||
43 | |||
44 | /** |
||
45 | * Import response metadata (nothing in this case) from another response. |
||
46 | * |
||
47 | * @param Response $otherResponse The other response to import information from. |
||
48 | * |
||
49 | * @author David Zülke <[email protected]> |
||
50 | * @since 1.0.0 |
||
51 | */ |
||
52 | public function merge(Response $otherResponse) |
||
56 | |||
57 | /** |
||
58 | * Redirect externally. Not implemented here. |
||
59 | * |
||
60 | * @param mixed $to Where to redirect. |
||
61 | * |
||
62 | * @throws \BadMethodCallException |
||
63 | * |
||
64 | * @author David Zülke <[email protected]> |
||
65 | * @since 1.0.0 |
||
66 | */ |
||
67 | public function setRedirect($to) |
||
71 | |||
72 | /** |
||
73 | * Get info about the set redirect. Not implemented here. |
||
74 | * |
||
75 | * @return array An assoc array of redirect info, or null if none set. |
||
76 | * |
||
77 | * @throws \BadMethodCallException |
||
78 | * |
||
79 | * @author David Zülke <[email protected]> |
||
80 | * @since 1.0.0 |
||
81 | */ |
||
82 | public function getRedirect() |
||
86 | |||
87 | /** |
||
88 | * Check if a redirect is set. Not implemented here. |
||
89 | * |
||
90 | * @return bool true, if a redirect is set, otherwise false |
||
91 | * |
||
92 | * @throws \BadMethodCallException |
||
93 | * |
||
94 | * @author David Zülke <[email protected]> |
||
95 | * @since 1.0.0 |
||
96 | */ |
||
97 | public function hasRedirect() |
||
101 | |||
102 | /** |
||
103 | * Clear any set redirect information. Not implemented here. |
||
104 | * |
||
105 | * @throws \BadMethodCallException |
||
106 | * |
||
107 | * @author David Zülke <[email protected]> |
||
108 | * @since 1.0.0 |
||
109 | */ |
||
110 | public function clearRedirect() |
||
114 | |||
115 | /** |
||
116 | * Set the shell exit code of this response. |
||
117 | * |
||
118 | * @param int $exitCode The exit code. |
||
119 | * |
||
120 | * @author David Zülke <[email protected]> |
||
121 | * @since 1.0.0 |
||
122 | */ |
||
123 | public function setExitCode($exitCode) |
||
127 | |||
128 | /** |
||
129 | * Get the shell exit code of this response. |
||
130 | * |
||
131 | * @return int The exit code. |
||
132 | * |
||
133 | * @author David Zülke <[email protected]> |
||
134 | * @since 1.0.0 |
||
135 | */ |
||
136 | public function getExitCode() |
||
140 | |||
141 | /** |
||
142 | * Determine whether the content in the response may be modified by appending |
||
143 | * or prepending data using string operations. Typically false for streams, |
||
144 | * and for responses like XMLRPC where the content is an array. |
||
145 | * |
||
146 | * @return bool If the content can be treated as / changed like a string. |
||
147 | * |
||
148 | * @author David Zülke <[email protected]> |
||
149 | * @since 1.0.0 |
||
150 | */ |
||
151 | public function isContentMutable() |
||
155 | |||
156 | /** |
||
157 | * Send all response data to the client. |
||
158 | * |
||
159 | * @author David Zülke <[email protected]> |
||
160 | * @since 1.0.0 |
||
161 | */ |
||
162 | public function send(OutputType $outputType = null) |
||
168 | |||
169 | /** |
||
170 | * Clear all response data. |
||
171 | * |
||
172 | * @author David Zülke <[email protected]> |
||
173 | * @since 1.0.0 |
||
174 | */ |
||
175 | public function clear() |
||
180 | |||
181 | /** |
||
182 | * Send the content for this response |
||
183 | * |
||
184 | * @author David Zülke <[email protected]> |
||
185 | * @since 1.0.0 |
||
186 | */ |
||
187 | protected function sendContent() |
||
197 | |||
198 | /** |
||
199 | * Call exit() and submit the exit code. |
||
200 | * This is called by PHP during script shutdown. |
||
201 | * It gets registered as a shutdown function in ConsoleResponse::send(). |
||
202 | * |
||
203 | * @author David Zülke <[email protected]> |
||
204 | * @since 1.0.0 |
||
205 | */ |
||
206 | public function sendExit() |
||
210 | } |
||
211 |
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.