1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Contract\Core\Entity; |
4: | |
5: | use Salient\Contract\Container\ContainerInterface; |
6: | use Salient\Contract\Core\ListConformity; |
7: | use LogicException; |
8: | |
9: | /** |
10: | * @api |
11: | */ |
12: | interface Constructible |
13: | { |
14: | /** |
15: | * Get an instance from an array |
16: | * |
17: | * Values in `$data` are applied to: |
18: | * |
19: | * 1. Constructor parameters |
20: | * 2. Writable properties |
21: | * 3. Dynamic properties (if the class implements {@see Extensible}) |
22: | * |
23: | * If the class implements {@see Normalisable}, identifiers are normalised |
24: | * for comparison. |
25: | * |
26: | * If the class implements {@see Treeable} and `$parent` is given, the |
27: | * instance is added to `$parent` as a child. |
28: | * |
29: | * @param mixed[] $data |
30: | * @param static|null $parent |
31: | * @return static |
32: | * @throws LogicException if any values in `$data` cannot be applied to the |
33: | * class. |
34: | */ |
35: | public static function construct( |
36: | array $data, |
37: | ?object $parent = null, |
38: | ?ContainerInterface $container = null |
39: | ); |
40: | |
41: | /** |
42: | * Get instances from arrays |
43: | * |
44: | * Values in `$data` arrays are applied as per |
45: | * {@see Constructible::construct()}. |
46: | * |
47: | * @template TKey of array-key |
48: | * |
49: | * @param iterable<TKey,mixed[]> $data |
50: | * @param ListConformity::* $conformity |
51: | * @param static|null $parent |
52: | * @return iterable<TKey,static> |
53: | * @throws LogicException if any values in `$data` arrays cannot be applied |
54: | * to the class. |
55: | */ |
56: | public static function constructMultiple( |
57: | iterable $data, |
58: | int $conformity = ListConformity::NONE, |
59: | ?object $parent = null, |
60: | ?ContainerInterface $container = null |
61: | ): iterable; |
62: | } |
63: |