| 1: | <?php |
| 2: | namespace TIC\DormBundle\Hydration; |
| 3: | |
| 4: | use Doctrine\ORM\Internal\Hydration\ObjectHydrator; |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | class ExtrasHydrator extends ObjectHydrator |
| 15: | { |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | protected function hydrateAllData(): array |
| 23: | { |
| 24: | $result = array(); |
| 25: | |
| 26: | foreach (parent::hydrateAllData() as $row) { |
| 27: | if (! \is_object($row[0])) continue; |
| 28: | |
| 29: | foreach ($row as $field => $value) { |
| 30: | if (! \is_int($field)) $this->setExtraField($row[0], $field, $value); |
| 31: | } |
| 32: | $result[] = $row[0]; |
| 33: | } |
| 34: | |
| 35: | return $result; |
| 36: | } |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | protected function setExtraField($object, $property, $value) |
| 44: | { |
| 45: | $mutator = 'set' . \ucfirst($property); |
| 46: | if (\method_exists($object, $mutator)) return \call_user_func(array($object, $mutator), $value); |
| 47: | if (\property_exists($object, $property)) $object->{$property} = $value; |
| 48: | } |
| 49: | |
| 50: | } |
| 51: | |