42 public function remove($domain =
null, $path =
null, $name =
null)
44 $cookies = $this->
all($domain, $path, $name,
false,
false);
45 $this->cookies = array_filter($this->cookies,
function (
Cookie $cookie) use (
$cookies) {
46 return !in_array($cookie,
$cookies,
true);
54 $this->cookies = array_filter($this->cookies,
function (
Cookie $cookie) {
63 $currentTime = time();
64 $this->cookies = array_filter($this->cookies,
function (
Cookie $cookie) use ($currentTime) {
65 return !$cookie->
getExpires() || $currentTime < $cookie->getExpires();
71 public function all($domain =
null, $path =
null, $name =
null, $skipDiscardable =
false, $skipExpired =
true)
73 return array_values(array_filter($this->cookies,
function (
Cookie $cookie) use (
80 return false === (($name && $cookie->
getName() != $name) ||
92 if ($result !==
true) {
93 if ($this->strictMode) {
96 $this->removeCookieIfEmpty($cookie);
102 foreach ($this->cookies as $i => $c) {
105 if ($c->getPath() != $cookie->
getPath() ||
106 $c->getDomain() != $cookie->
getDomain() ||
107 $c->getPorts() != $cookie->
getPorts() ||
108 $c->getName() != $cookie->
getName()
114 if (!$cookie->
getDiscard() && $c->getDiscard()) {
115 unset($this->cookies[$i]);
120 if ($cookie->
getExpires() > $c->getExpires()) {
121 unset($this->cookies[$i]);
126 if ($cookie->
getValue() !== $c->getValue()) {
127 unset($this->cookies[$i]);
135 $this->cookies[] = $cookie;
148 return json_encode(array_map(
function (Cookie $cookie) {
149 return $cookie->toArray();
150 }, $this->
all(
null,
null,
null,
true,
true)));
158 $data = json_decode($data,
true);
160 $this->cookies = array();
162 $this->cookies = array_map(
function (array $cookie) {
163 return new Cookie($cookie);
173 public function count()
175 return count($this->cookies);
185 return new \ArrayIterator($this->cookies);
190 if ($cookieHeader = $response->getHeader(
'Set-Cookie')) {
192 foreach ($cookieHeader as $cookie) {
193 if ($parsed = $request
194 ? $parser->parseCookie($cookie, $request->getHost(), $request->getPath())
195 : $parser->parseCookie($cookie)
198 foreach ($parsed[
'cookies'] as $key => $value) {
201 $row[
'value'] = $value;
202 unset($row[
'cookies']);
213 $cookies = $this->
all($request->getHost(), $request->getPath());
215 foreach (
$cookies as $index => $cookie) {
216 if (!$cookie->
matchesPort($request->getPort()) || ($cookie->
getSecure() && $request->getScheme() !=
'https')) {
230 private function removeCookieIfEmpty(Cookie $cookie)
232 $cookieValue = $cookie->getValue();
233 if ($cookieValue ===
null || $cookieValue ===
'') {
234 $this->
remove($cookie->getDomain(), $cookie->getPath(), $cookie->getName());