public function onKernelResponse(FilterResponseEvent $event) { // Only run on the Master request if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { return; } // Get the response and encrypt the requested cookies $response = $event->getResponse(); foreach ($response->headers->getCookies() as $cookie) { if (!$this->isEncryptedable($cookie->getName())) { continue; } $response->headers->removeCookie($cookie->getName(), $cookie->getPath(), $cookie->getDomain()); $encryptedCookie = new Cookie($cookie->getName(), $this->encrypter->encrypt($cookie->getValue()), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); $response->headers->setCookie($encryptedCookie, $cookie->getPath(), $cookie->getDomain()); } }
function let(EncryptionInterface $encryption) { $encryption->encrypt('test')->willReturn('dGVzdA=='); $encryption->decrypt('dGVzdA==')->willReturn('test'); $this->beConstructedWith(['session'], $encryption); }