1 | <?php |
||
2 | /** |
||
3 | * |
||
4 | * This file is part of the Aura project for PHP. |
||
5 | * |
||
6 | * @package Aura.Marshal |
||
7 | * |
||
8 | * @license https://opensource.org/licenses/mit-license.php MIT |
||
9 | * |
||
10 | */ |
||
11 | namespace Aura\Marshal\Entity; |
||
12 | |||
13 | /** |
||
14 | * |
||
15 | * Creates a new entity object for a type. |
||
16 | * |
||
17 | * @package Aura.Marshal |
||
18 | * |
||
19 | */ |
||
20 | class Builder implements BuilderInterface |
||
21 | { |
||
22 | /** |
||
23 | * |
||
24 | * The class to use for new instances. |
||
25 | * |
||
26 | * @var class-string<GenericEntity> |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
27 | * |
||
28 | */ |
||
29 | protected $class = 'Aura\Marshal\Entity\GenericEntity'; |
||
30 | |||
31 | /** |
||
32 | * |
||
33 | * Creates a new entity object. |
||
34 | * |
||
35 | * @param array<int|string, mixed> $data Data to load into the entity. |
||
36 | * |
||
37 | * @return GenericEntity |
||
38 | * |
||
39 | */ |
||
40 | public function newInstance(array $data) |
||
41 | { |
||
42 | $class = $this->class; |
||
43 | $entity = new $class; |
||
44 | |||
45 | // set fields |
||
46 | foreach ($data as $field => $value) { |
||
47 | $entity->$field = $value; |
||
48 | } |
||
49 | |||
50 | return $entity; |
||
51 | } |
||
52 | } |
||
53 |