Mercurial > hg > cmmr2012-drupal-site
comparison vendor/zendframework/zend-diactoros/src/Server.php @ 2:5311817fb629
Theme updates
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 13:19:18 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
1:0b0e5f3b1e83 | 2:5311817fb629 |
---|---|
1 <?php | 1 <?php |
2 /** | 2 /** |
3 * Zend Framework (http://framework.zend.com/) | 3 * @see https://github.com/zendframework/zend-diactoros for the canonical source repository |
4 * | 4 * @copyright Copyright (c) 2015-2018 Zend Technologies USA Inc. (http://www.zend.com) |
5 * @see http://github.com/zendframework/zend-diactoros for the canonical source repository | |
6 * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com) | |
7 * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License | 5 * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License |
8 */ | 6 */ |
9 | 7 |
10 namespace Zend\Diactoros; | 8 namespace Zend\Diactoros; |
11 | 9 |
12 use OutOfBoundsException; | 10 use OutOfBoundsException; |
11 use Psr\Http\Message\ResponseInterface; | |
13 use Psr\Http\Message\ServerRequestInterface; | 12 use Psr\Http\Message\ServerRequestInterface; |
14 use Psr\Http\Message\ResponseInterface; | 13 |
14 use function property_exists; | |
15 | 15 |
16 /** | 16 /** |
17 * "Serve" incoming HTTP requests | 17 * "Serve" incoming HTTP requests |
18 * | 18 * |
19 * Given a callback, takes an incoming request, dispatches it to the | 19 * Given a callback, takes an incoming request, dispatches it to the |
20 * callback, and then sends a response. | 20 * callback, and then sends a response. |
21 * | |
22 * @deprecated since 1.8.0. We recommend using the `RequestHandlerRunner` class | |
23 * from the zendframework/zend-httphandlerrunner package instead. | |
21 */ | 24 */ |
22 class Server | 25 class Server |
23 { | 26 { |
24 /** | 27 /** |
25 * @var callable | 28 * @var callable |
148 * "Listen" to an incoming request | 151 * "Listen" to an incoming request |
149 * | 152 * |
150 * If provided a $finalHandler, that callable will be used for | 153 * If provided a $finalHandler, that callable will be used for |
151 * incomplete requests. | 154 * incomplete requests. |
152 * | 155 * |
153 * Output buffering is enabled prior to invoking the attached | |
154 * callback; any output buffered will be sent prior to any | |
155 * response body content. | |
156 * | |
157 * @param null|callable $finalHandler | 156 * @param null|callable $finalHandler |
158 */ | 157 */ |
159 public function listen(callable $finalHandler = null) | 158 public function listen(callable $finalHandler = null) |
160 { | 159 { |
161 $callback = $this->callback; | 160 $callback = $this->callback; |
162 | 161 |
163 ob_start(); | |
164 $bufferLevel = ob_get_level(); | |
165 | |
166 $response = $callback($this->request, $this->response, $finalHandler); | 162 $response = $callback($this->request, $this->response, $finalHandler); |
167 if (! $response instanceof ResponseInterface) { | 163 if (! $response instanceof ResponseInterface) { |
168 $response = $this->response; | 164 $response = $this->response; |
169 } | 165 } |
170 $this->getEmitter()->emit($response, $bufferLevel); | 166 |
167 $this->getEmitter()->emit($response); | |
171 } | 168 } |
172 | 169 |
173 /** | 170 /** |
174 * Retrieve the current response emitter. | 171 * Retrieve the current response emitter. |
175 * | 172 * |