Skip to content

Commit b06a3d1

Browse files
author
Jamie Hannaford
committed
add convenience setter
1 parent 4b56b34 commit b06a3d1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Common/HydratorStrategyTrait.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@ private function hydrate(array $data, array $aliases = [])
2424
}
2525
}
2626
}
27+
28+
private function set($key, $property, array $data, callable $fn = null)
29+
{
30+
if (isset($data[$key]) && property_exists($this, $property)) {
31+
$value = $fn ? call_user_func($fn, $data[$key]) : $data[$key];
32+
$this->$property = $value;
33+
}
34+
}
2735
}

0 commit comments

Comments
 (0)