Conditions | 2 |
Paths | 2 |
Total Lines | 32 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
32 | public function createFromArray(array $array): Entity |
||
33 | { |
||
34 | /** |
||
35 | * @var Entity $entity |
||
36 | */ |
||
37 | $reflector = new \ReflectionClass($this->entityClass); |
||
38 | |||
39 | $entity = $reflector->newInstanceWithoutConstructor(); |
||
40 | |||
41 | $columns = $entity::getColumns(); |
||
42 | unset($columns['id'], $columns['modified'], $columns['created']); |
||
43 | |||
44 | $arguments = []; |
||
45 | |||
46 | foreach ($columns as $column => $type) { |
||
47 | $property = new EntityProperty($type); |
||
48 | |||
49 | $arguments[$column] = $property->formatValueForEntity($array[$column]); |
||
50 | } |
||
51 | |||
52 | $entity = $reflector->newInstanceArgs($arguments); |
||
53 | $entity->set('id', (int)$array['id']); |
||
54 | $entity->set('modified', new \DateTime($array['modified'])); |
||
55 | $entity->set('created', new \DateTime($array['created'])); |
||
56 | |||
57 | /** |
||
58 | * Mark entity as unaltered |
||
59 | */ |
||
60 | $entity->setUnaltered(); |
||
61 | |||
62 | return $entity; |
||
63 | } |
||
64 | } |
||
65 |