18
18
use Cake \Filesystem \File ;
19
19
use Cake \Http \Cookie \Cookie ;
20
20
use Cake \Http \Cookie \CookieCollection ;
21
+ use Cake \Http \Cookie \CookieInterface ;
21
22
use Cake \Log \Log ;
22
23
use Cake \Network \CorsBuilder ;
23
24
use Cake \Network \Exception \NotFoundException ;
@@ -1938,7 +1939,9 @@ public function cookie($options = null)
1938
1939
return null ;
1939
1940
}
1940
1941
1941
- return $ this ->_cookies ->get ($ options )->toArrayResponse ();
1942
+ $ cookie = $ this ->_cookies ->get ($ options );
1943
+
1944
+ return $ this ->toArrayResponse ($ cookie );
1942
1945
}
1943
1946
1944
1947
$ options += [
@@ -2042,7 +2045,9 @@ public function getCookie($name)
2042
2045
return null ;
2043
2046
}
2044
2047
2045
- return $ this ->_cookies ->get ($ name )->toArrayResponse ();
2048
+ $ cookie = $ this ->_cookies ->get ($ name );
2049
+
2050
+ return $ this ->toArrayResponse ($ cookie );
2046
2051
}
2047
2052
2048
2053
/**
@@ -2056,12 +2061,42 @@ public function getCookies()
2056
2061
{
2057
2062
$ out = [];
2058
2063
foreach ($ this ->_cookies as $ cookie ) {
2059
- $ out [$ cookie ->getName ()] = $ cookie ->toArrayResponse ();
2064
+ $ out [$ cookie ->getName ()] = $ this ->toArrayResponse ($ cookie );
2060
2065
}
2061
2066
2062
2067
return $ out ;
2063
2068
}
2064
2069
2070
+ /**
2071
+ * Convert the cookie into an array of its properties.
2072
+ *
2073
+ * This method is compatible with the historical behavior of Cake\Http\Response,
2074
+ * where `httponly` is `httpOnly` and `expires` is `expire`
2075
+ *
2076
+ * @param \Cake\Http\Cookie\CookieInterface $cookie Cookie object.
2077
+ * @return array
2078
+ */
2079
+ protected function toArrayResponse (CookieInterface $ cookie )
2080
+ {
2081
+ if ($ cookie instanceof Cookie) {
2082
+ return $ cookie ->toArrayResponse ();
2083
+ } elseif ($ cookie ->getExpiry ()) {
2084
+ $ expires = $ cookie ->getExpiry ()->format ('U ' );
2085
+ } else {
2086
+ $ expires = '' ;
2087
+ }
2088
+
2089
+ return [
2090
+ 'name ' => $ cookie ->getName (),
2091
+ 'value ' => $ cookie ->getValue (),
2092
+ 'path ' => $ cookie ->getPath (),
2093
+ 'domain ' => $ cookie ->getDomain (),
2094
+ 'secure ' => $ cookie ->isSecure (),
2095
+ 'httpOnly ' => $ cookie ->isHttpOnly (),
2096
+ 'expire ' => $ expires
2097
+ ];
2098
+ }
2099
+
2065
2100
/**
2066
2101
* Get the CookieCollection from the response
2067
2102
*
0 commit comments