public function testToString() { $cookie = new Cookie('foo', 'bar'); $this->assertSame('foo=bar', (string) $cookie); $cookie->setExpires(2000000000); $this->assertSame('foo=bar; Expires=Wed, 18 May 2033 03:33:20 +0000', (string) $cookie); $cookie->setExpires(0)->setDomain('example.com'); $this->assertSame('foo=bar; Domain=example.com', (string) $cookie); $cookie->setDomain(null)->setPath('/'); $this->assertSame('foo=bar; Path=/', (string) $cookie); $cookie->setPath(null)->setSecure(true); $this->assertSame('foo=bar; Secure', (string) $cookie); $cookie->setHttpOnly(true); $this->assertSame('foo=bar; Secure; HttpOnly', (string) $cookie); }
/** * Writes the session cookie to the Response. * * @param \Brick\Http\Response $response * * @return void */ public function handleResponse(Response $response) { $lifetime = $this->cookieParams['lifetime']; $expires = $lifetime == 0 ? 0 : time() + $lifetime; $cookie = new Cookie($this->cookieParams['name'], $this->id); $cookie->setExpires($expires)->setPath($this->cookieParams['path'])->setDomain($this->cookieParams['domain'])->setSecure($this->cookieParams['secure'])->setHttpOnly($this->cookieParams['http-only']); $response->setCookie($cookie); }