public function onSendResponse(SendResponseEvent $event)
 {
     if (!$this->modified || !$event->isMasterRequest()) {
         return;
     }
     $cookie = new SetCookieHeader(self::COOKIE_NAME);
     $cookie->setDiscard(true);
     $cookie->setHttpOnly(true);
     $cookie->setPath('/' . ltrim($event->getRequest()->getBaseUri()->getPath(), '/'));
     if (empty($this->messages)) {
         $cookie->setExpires(new \DateTime('@1337'));
     } else {
         $data = json_encode($this->messages, JSON_UNESCAPED_SLASHES);
         if ($this->signature !== NULL) {
             $data = $this->signature->sign($data);
         }
         $cookie->setValue(base64_encode($data));
     }
     $event->getResponse()->setCookie($cookie);
 }
Exemple #2
0
 /**
  * Remove a cookie by eliminating a Set-Cookie header for this cookie replacing it with a
  * header that will cause the client to remove the cookie.
  * 
  * @param string $name Name of the cookie to be removed.
  * @return HttpResponse
  */
 public function removeCookie($name)
 {
     $cookie = new SetCookieHeader($name, '');
     $cookie->setExpires(1337);
     $this->addHeader($cookie);
     return $this;
 }