Skip to content

Commit

Permalink
Move toArrayResponse() method to Http\Response.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Pustułka committed Apr 20, 2017
1 parent d5d6664 commit f46432f
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/Http/Response.php
Expand Up @@ -18,6 +18,7 @@
use Cake\Filesystem\File;
use Cake\Http\Cookie\Cookie;
use Cake\Http\Cookie\CookieCollection;
use Cake\Http\Cookie\CookieInterface;
use Cake\Log\Log;
use Cake\Network\CorsBuilder;
use Cake\Network\Exception\NotFoundException;
Expand Down Expand Up @@ -1938,7 +1939,9 @@ public function cookie($options = null)
return null;
}

return $this->_cookies->get($options)->toArrayResponse();
$cookie = $this->_cookies->get($options);

return $this->toArrayResponse($cookie);
}

$options += [
Expand Down Expand Up @@ -2042,7 +2045,9 @@ public function getCookie($name)
return null;
}

return $this->_cookies->get($name)->toArrayResponse();
$cookie = $this->_cookies->get($name);

return $this->toArrayResponse($cookie);
}

/**
Expand All @@ -2056,12 +2061,42 @@ public function getCookies()
{
$out = [];
foreach ($this->_cookies as $cookie) {
$out[$cookie->getName()] = $cookie->toArrayResponse();
$out[$cookie->getName()] = $this->toArrayResponse($cookie);
}

return $out;
}

/**
* Convert the cookie into an array of its properties.
*
* This method is compatible with the historical behavior of Cake\Http\Response,
* where `httponly` is `httpOnly` and `expires` is `expire`
*
* @param \Cake\Http\Cookie\CookieInterface $cookie Cookie object.
* @return array
*/
protected function toArrayResponse(CookieInterface $cookie)
{
if ($cookie instanceof Cookie) {
return $cookie->toArrayResponse();
} elseif ($cookie->getExpiry()) {
$expires = $cookie->getExpiry()->format('U');
} else {
$expires = '';
}

return [
'name' => $cookie->getName(),
'value' => $cookie->getValue(),
'path' => $cookie->getPath(),
'domain' => $cookie->getDomain(),
'secure' => $cookie->isSecure(),
'httpOnly' => $cookie->isHttpOnly(),
'expire' => $expires
];
}

/**
* Get the CookieCollection from the response
*
Expand Down

0 comments on commit f46432f

Please sign in to comment.