Skip to content

Commit f07d834

Browse files
[1.12] IteratorAggregate for Cookie (#653)
* IteratorAggregate for Cookie Was in a situation where I wanted a plain-array version of Cookie, was a little sad that I couldn't unpack it. Previously: var_dump([...$cookie]); object(TypeError)#1261 (7) { ["message":protected]=> string(44) "Only arrays and Traversables can be unpacked" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) (...) Now: var_dump([...$cookie]); array(13) { ["name"]=> string(9) "PHPSESSID" ["value"]=> string(26) "<censored>" ["domain"]=> string(13) "<censored>" ["path"]=> string(1) "/" ["expires"]=> int(-1) ["size"]=> int(35) ["httpOnly"]=> bool(true) ["secure"]=> bool(false) ["session"]=> bool(true) ["priority"]=> string(6) "Medium" ["sameParty"]=> bool(false) ["sourceScheme"]=> string(6) "Secure" ["sourcePort"]=> int(443) } * Properly declare return type * Add missing backlash --------- Co-authored-by: Graham Campbell <GrahamCampbell@users.noreply.github.com>
1 parent fa06bc3 commit f07d834

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Cookies/Cookie.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace HeadlessChromium\Cookies;
1313

14-
class Cookie implements \ArrayAccess
14+
class Cookie implements \ArrayAccess, \IteratorAggregate
1515
{
1616
/**
1717
* @var array
@@ -102,4 +102,9 @@ public static function create($name, $value, array $params = [])
102102

103103
return new self($params);
104104
}
105+
106+
public function getIterator(): \ArrayIterator
107+
{
108+
return new \ArrayIterator($this->data);
109+
}
105110
}

0 commit comments

Comments
 (0)