We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ac34262 commit 7a3aecbCopy full SHA for 7a3aecb
src/Type/TypedArray.php
@@ -29,6 +29,24 @@ public function getType(): string
29
return $this->type;
30
}
31
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
50
protected function isValueValid($value): bool
51
{
52
if ($this->isNullAllowed() && $value == null) {
0 commit comments