diff vendor/zendframework/zend-diactoros/src/Response/SapiEmitter.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 7a779792577d
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/zendframework/zend-diactoros/src/Response/SapiEmitter.php	Wed Nov 29 16:09:58 2017 +0000
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @see       http://github.com/zendframework/zend-diactoros for the canonical source repository
+ * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license   https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
+ */
+
+namespace Zend\Diactoros\Response;
+
+use Psr\Http\Message\ResponseInterface;
+use RuntimeException;
+
+class SapiEmitter implements EmitterInterface
+{
+    use SapiEmitterTrait;
+
+    /**
+     * Emits a response for a PHP SAPI environment.
+     *
+     * Emits the status line and headers via the header() function, and the
+     * body content via the output buffer.
+     *
+     * @param ResponseInterface $response
+     * @param null|int $maxBufferLevel Maximum output buffering level to unwrap.
+     */
+    public function emit(ResponseInterface $response, $maxBufferLevel = null)
+    {
+        if (headers_sent()) {
+            throw new RuntimeException('Unable to emit response; headers already sent');
+        }
+
+        $response = $this->injectContentLength($response);
+
+        $this->emitStatusLine($response);
+        $this->emitHeaders($response);
+        $this->flush($maxBufferLevel);
+        $this->emitBody($response);
+    }
+
+    /**
+     * Emit the message body.
+     *
+     * @param ResponseInterface $response
+     */
+    private function emitBody(ResponseInterface $response)
+    {
+        echo $response->getBody();
+    }
+}