# Class HttpSoft\Cookie\CookieSendMiddleware

Middleware that implements Psr\Http\Server\MiddlewareInterface.

Source code on GitHub.

use HttpSoft\Cookie\CookieManager;
use HttpSoft\Cookie\CookieSendMiddleware;

 * @var HttpSoft\Cookie\CookieInterface[] $cookies
 * @var HttpSoft\Emitter\EmitterInterface $emitter
 * @var Psr\Http\Message\ResponseInterface $response
 * @var Psr\Http\Message\ServerRequestInterface $request
 * @var Psr\Http\Server\RequestHandlerInterface $handler

// Set cookies to the manager
$manager = new CookieManager($cookies);

$middleware = new CookieSendMiddleware($manager);
// If do not need to remove previously set cookies from the response
$middleware = new CookieSendMiddleware($manager, false);

// Set all cookie to the response for sending
$response = $middleware->process($request, $handler);

// Emit a response to the client

# Public methods

 * @param CookieManagerInterface $cookies object with cookies to set in response.
 * @param bool $removeResponseCookies whether to remove previously set cookies from the response.
public function __construct(CookieManagerInterface $cookies, bool $removeResponseCookies = true);

The methods that are defined in the Psr\Http\Server\MiddlewareInterface interface, are shown below.

# process

Sets all cookie to the response and returns a clone instance of the response with the cookies set.

public function process(
    ServerRequestInterface $request, 
    RequestHandlerInterface $handler
): ResponseInterface;