Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Zend Diactoros Laravel Package

zendframework/zend-diactoros

zendframework/zend-diactoros provides PSR-7 HTTP message implementations for PHP, including ServerRequest, Response, Stream, UploadedFile and Uri. Useful for building middleware, APIs and frameworks with interoperable request/response handling.

View on GitHub
Deep Wiki
Context7

Emitting Responses

Deprecated

Emitters are deprecated from Diactoros starting with version 1.8.0. The functionality is now available for any PSR-7 implementation via the package zendframework/zend-httphandlerrunner. We suggest using that functionality instead.

If you are using a non-SAPI PHP implementation and wish to use the Server class, or if you do not want to use the Server implementation but want to emit a response, this package provides an interface, Zend\Diactoros\Response\EmitterInterface, defining a method emit() for emitting the response.

Diactoros provides two implementations currently, both for working with traditional Server API (SAPI) implementations: Zend\Diactoros\Response\SapiEmitter and Zend\Diactoros\Response\SapiStreamEmitter. Each uses the native header() PHP function to emit headers, and echo() to emit the response body.

If you are using a non-SAPI implementation, you will need to create your own EmitterInterface implementation.

For example, the SapiEmitter implementation of the EmitterInterface can be used thus:

$response = new Zend\Diactoros\Response();
$response->getBody()->write("some content\n");
$emitter = new Zend\Diactoros\Response\SapiEmitter();
$emitter->emit($response);

Emitting Ranges of streamed Files

The SapiStreamEmitter is useful when you want to emit a Content-Range. As an example, to stream a range of bytes from a file to a client, the client can pass the following header:

Range: bytes=1024-2047

Your application would then populate the response with a Content-Range header:

$range = $request->getHeaderLine('range');
$range = str_replace('=', ' ', $range);

$body = new Stream($pathToFile);
$size = $body->getSize();
$range .= '/' . $size;

$response = new Response($body);
$response = $response->withHeader('Content-Range', $range);

(Note: you will likely want to ensure the range specified falls within the content size of the streamed body!)

The SapiStreamEmitter detects the Content-Range header and emits only the bytes specified.

$emitter = new SapiStreamEmitter();
$emitter->emit($response);

The SapiStreamEmitter may be used in place of the SapiEmitter, even when not sending files. However, unlike the SapiEmitter, it will emit a chunk of content at a time instead of the full content at once, which could lead to performance overhead. The default chunk size is 8192 bytes.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata