Skip to content

Commit db16738

Browse files
committed
Only HttpCookies
1 parent 2074766 commit db16738

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/Http/Config/ServerRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Valar\Http\Config;
77

88
use Mvc5\Arg;
9+
use Mvc5\Cookie\HttpCookies;
910

1011
trait ServerRequest
1112
{
@@ -37,8 +38,7 @@ function getAttributes() : array
3738
*/
3839
function getCookieParams() : array
3940
{
40-
/** @var array|\Traversable $cookies */
41-
return is_array($cookies = $this[Arg::COOKIES] ?? []) ? $cookies : \iterator_to_array($cookies);
41+
return $this[Arg::COOKIES]->all();
4242
}
4343

4444
/**
@@ -98,7 +98,7 @@ function withoutAttribute($name)
9898
*/
9999
function withCookieParams(array $cookies)
100100
{
101-
return $this->with(Arg::COOKIES, $cookies);
101+
return $this->with(Arg::COOKIES, new HttpCookies($cookies));
102102
}
103103

104104
/**

src/Http/ServerRequest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Valar\Http;
77

88
use Mvc5\Arg;
9+
use Mvc5\Cookie\HttpCookies;
910
use Mvc5\Http\HttpHeaders;
1011
use Psr\Http\Message\ServerRequestInterface;
1112
use Zend\Diactoros\PhpInputStream;
@@ -40,10 +41,15 @@ function __construct($config = [])
4041
ServerRequestFactory::marshalUriFromServer($server, \iterator_to_array($config[Arg::HEADERS]))
4142
);
4243

44+
!isset($config[Arg::COOKIES]) &&
45+
$config[Arg::COOKIES] = new HttpCookies($_COOKIE);
46+
47+
is_array($config[Arg::COOKIES]) &&
48+
$config[Arg::COOKIES] = new HttpCookies($config[Arg::COOKIES]);
49+
4350
!isset($config[Arg::ARGS]) && $config[Arg::ARGS] = $_GET;
4451
!isset($config[Arg::ATTRIBUTES]) && $config[Arg::ATTRIBUTES] = [];
4552
!isset($config[Arg::BODY]) && $config[Arg::BODY] = new PhpInputStream;
46-
!isset($config[Arg::COOKIES]) && $config[Arg::COOKIES] = $_COOKIE;
4753
!isset($config[Arg::DATA]) && $config[Arg::DATA] = $_POST;
4854
!isset($config[Arg::FILES]) && $config[Arg::FILES] = ServerRequestFactory::normalizeFiles($_FILES);
4955
!isset($config[Arg::METHOD]) && $config[Arg::METHOD] = $server['REQUEST_METHOD'] ?? 'GET';

tests/Http/ServerRequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function test_get_cookie_params()
4646
/**
4747
*
4848
*/
49-
function test_get_cookie_params_from_traversable()
49+
function test_get_cookie_params_from_http_cookies()
5050
{
5151
$request = new ServerRequest(['cookies' => new HttpCookies(['foo' => 'bar'])]);
5252

0 commit comments

Comments
 (0)