View file vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php

File size: 970B
  1. <?php
  2.  
  3. namespace Illuminate\Cookie\Middleware;
  4.  
  5. use Closure;
  6. use Illuminate\Contracts\Cookie\QueueingFactory as CookieJar;
  7.  
  8. class AddQueuedCookiesToResponse
  9. {
  10. /**
  11. * The cookie jar instance.
  12. *
  13. * @var \Illuminate\Contracts\Cookie\QueueingFactory
  14. */
  15. protected $cookies;
  16.  
  17. /**
  18. * Create a new CookieQueue instance.
  19. *
  20. * @param \Illuminate\Contracts\Cookie\QueueingFactory $cookies
  21. * @return void
  22. */
  23. public function __construct(CookieJar $cookies)
  24. {
  25. $this->cookies = $cookies;
  26. }
  27.  
  28. /**
  29. * Handle an incoming request.
  30. *
  31. * @param \Illuminate\Http\Request $request
  32. * @param \Closure $next
  33. * @return mixed
  34. */
  35. public function handle($request, Closure $next)
  36. {
  37. $response = $next($request);
  38.  
  39. foreach ($this->cookies->getQueuedCookies() as $cookie) {
  40. $response->headers->setCookie($cookie);
  41. }
  42.  
  43. return $response;
  44. }
  45. }