AddQueuedCookiesToResponse.php
TLDR
This file AddQueuedCookiesToResponse.php
is a middleware class that adds queued cookies to the response.
Methods
handle
This method handles an incoming request by adding queued cookies to the response.
Classes
Class: AddQueuedCookiesToResponse
This class is a middleware that adds queued cookies to the response. It has the following methods:
-
__construct
: Initializes the class by setting the cookie jar instance. -
handle
: Handles an incoming request by adding queued cookies to the response.
<?php
namespace Illuminate\Cookie\Middleware;
use Closure;
use Illuminate\Contracts\Cookie\QueueingFactory as CookieJar;
class AddQueuedCookiesToResponse
{
/**
* The cookie jar instance.
*
* @var \Illuminate\Contracts\Cookie\QueueingFactory
*/
protected $cookies;
/**
* Create a new CookieQueue instance.
*
* @param \Illuminate\Contracts\Cookie\QueueingFactory $cookies
* @return void
*/
public function __construct(CookieJar $cookies)
{
$this->cookies = $cookies;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
foreach ($this->cookies->getQueuedCookies() as $cookie) {
$response->headers->setCookie($cookie);
}
return $response;
}
}