예제 #1
0
 /**
  * Builds a Set-Cookie header value.
  *
  * @param  string $name   The cookie name.
  * @param  object $cookie The cookie instance.
  * @return string
  */
 protected static function _setCookieValue($name, $cookie)
 {
     if (!Cookie::isValidName($name)) {
         throw new Exception("Invalid Set-Cookie name `'{$name}'`.");
     }
     $data = $cookie->data();
     $parts = [];
     $parts[] = $name . '=' . rawurlencode($data['value']);
     if (isset($data['max-age'])) {
         $parts[] = 'Max-Age=' . (string) $data['max-age'];
     } elseif (isset($data['expires'])) {
         $parts[] = 'Expires=' . gmdate('D, d M Y H:i:s \\G\\M\\T', $data['expires']);
     }
     if ($data['path']) {
         $parts[] = 'Path=' . $data['path'];
     }
     if ($data['domain']) {
         $parts[] = 'Domain=' . $data['domain'];
     }
     if ($data['secure']) {
         $parts[] = 'Secure';
     }
     if ($data['httponly']) {
         $parts[] = 'HttpOnly';
     }
     return join('; ', $parts);
 }
예제 #2
0
파일: Cookies.php 프로젝트: crysalead/net
 /**
  * Builds a Cookie header value.
  *
  * @param  string $name   The cookie name.
  * @param  object $cookie The cookie instance.
  * @return string
  */
 protected static function _cookieValue($name, $cookie)
 {
     if (!Cookie::isValidName($name)) {
         throw new Exception("Invalid cookie name `'{$name}'`.");
     }
     $result = [];
     foreach ($cookie->data() as $value) {
         $result[] = $name . '=' . urlencode($value);
     }
     return join('; ', $result);
 }