Last active
June 8, 2024 08:33
-
-
Save BinaryKitten/2f50ba3ef9e264dbab1342f51e5bebab to your computer and use it in GitHub Desktop.
streamedPsrResponse Macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Providers; | |
use Illuminate\Http\Client\Response as HttpClientResponse; | |
use Illuminate\Support\ServiceProvider; | |
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory; | |
use Symfony\Component\HttpFoundation\StreamedResponse; | |
class AppServiceProvider extends ServiceProvider | |
{ | |
public function boot(): void | |
{ | |
HttpClientResponse::macro('toStreamedPsrResponse', function (int $responseBufferMaxLength = 16372): StreamedResponse { | |
return resolve(HttpFoundationFactory::class, [$responseBufferMaxLength]) | |
->createResponse($this->response, streamed: true); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment