public function persist(Session $session, ResponseInterface $response = null, $overwriteExistingCookie = false)
 {
     if (is_null($response)) {
         throw new InvalidArgumentException('You must pass an instance of ResponseInterface.');
     }
     $setCookies = SetCookies::fromResponse($response);
     //Cookie already set in response by a preceding middleware
     if (!$overwriteExistingCookie && $setCookies->has($this->config['cookie_name'])) {
         return $response;
     }
     $setCookie = SetCookie::create($this->config['cookie_name'])->withPath($this->config['cookie_path'])->withDomain($this->config['cookie_domain'])->withSecure($this->config['cookie_secure'])->withHttpOnly($this->config['cookie_httponly']);
     if ($session->wasDestroyed()) {
         $setCookie = $setCookie->withValue('')->withExpires(1);
     } else {
         $setCookie = $setCookie->withValue($session->getSessionId())->withExpires($this->config['cookie_lifetime'] == 0 ? 0 : time() + $this->config['cookie_lifetime']);
     }
     return $setCookies->with($setCookie)->renderIntoSetCookieHeader($response);
 }