Skip to content

Commit 7a3aecb

Browse files
committed
Bug fix: Https test failing
1 parent ac34262 commit 7a3aecb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Type/TypedArray.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ public function getType(): string
2929
return $this->type;
3030
}
3131

32+
public static function fromArray(array $data, bool $nullAllowed = false): static
33+
{
34+
$sa = new static();
35+
$sa->setNullAllowed($nullAllowed);
36+
37+
foreach ($data as $key => $value) {
38+
$type = $sa->getType();
39+
if ($value instanceof $type) {
40+
$sa->offsetSet($key, $value);
41+
} else {
42+
$obj = new ($sa->getType())($value);
43+
$sa->offsetSet($key, $obj);
44+
}
45+
}
46+
47+
return $sa;
48+
}
49+
3250
protected function isValueValid($value): bool
3351
{
3452
if ($this->isNullAllowed() && $value == null) {

0 commit comments

Comments
 (0)