Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function set(ServerRequestInterface $request, ResponseInterface $response, $name, $value, array $settings = [])
 {
     // ---------------------------------------------------
     //  Request cookies
     // ---------------------------------------------------
     $cookies = Cookies::fromRequest($request);
     if ($cookies->has($name)) {
         $cookie = $cookies->get($name)->withValue($value);
     } else {
         $cookie = Cookie::create($name, $value);
     }
     $request = $cookies->with($cookie)->renderIntoCookieHeader($request);
     // ---------------------------------------------------
     //  Response cookies
     // ---------------------------------------------------
     $domain = isset($settings['domain']) ? (string) $settings['domain'] : '';
     $path = isset($settings['path']) ? (string) $settings['path'] : '/';
     $ttl = isset($settings['ttl']) ? $settings['ttl'] : 0;
     $expires = isset($settings['expires']) ? $settings['expires'] : time() + $ttl;
     $secure = isset($settings['secure']) && $settings['secure'];
     $http_only = isset($settings['http_only']) && $settings['http_only'];
     $set_cookies = SetCookies::fromResponse($response);
     if ($set_cookies->has($name)) {
         $set_cookie = $set_cookies->get($name)->withValue($value);
     } else {
         $set_cookie = SetCookie::create($name, $value);
     }
     $set_cookie = $set_cookie->withDomain($domain)->withPath($path)->withSecure($secure)->withExpires(date(DATE_COOKIE, $expires))->withHttpOnly($http_only);
     $response = $set_cookies->with($set_cookie)->renderIntoSetCookieHeader($response);
     return [$request, $response];
 }
 public function testGetObscuredCookie()
 {
     $cookies = Cookies::fromCookieString('testcookie1=abcde;testcookie2=12345')->with(Cookie::create('testcookie3', new OpaqueProperty('vwxyz')));
     $request = $this->request->withAttribute('request_cookies', $cookies);
     $handler = new CookieHandler();
     $cookie = $handler->getCookie($request, 'testcookie3');
     $this->assertSame('vwxyz', $cookie);
 }