Skip to content

Commit 87e1caf

Browse files
committed
making Bag class has() method functionality similar to the one in get() method
1 parent 80eec2e commit 87e1caf

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Bag.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ public function getAll()
9090
*/
9191
public function has($name)
9292
{
93+
if (strpos($name, '[') !== false) {
94+
$names = explode('[', str_replace(']', '', $name));
95+
$key = array_shift($names);
96+
$item = isset($this->parameters[$key]) ? $this->parameters[$key] : [];
97+
98+
foreach ($names as $key) {
99+
if (!isset($item[$key])) {
100+
return false;
101+
}
102+
103+
$item = $item[$key];
104+
}
105+
106+
return isset($item);
107+
}
108+
93109
return isset($this->parameters[$name]);
94110
}
95111
}

0 commit comments

Comments
 (0)