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\Exception\InvalidDataException;
7: use Salient\Contract\HasConformity;
8:
9: /**
10: * @api
11: */
12: interface Constructible extends HasConformity
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. Declared and "magic" properties covered by {@see Writable} (if
22: * implemented by the class)
23: * 4. Dynamic properties (if the class implements {@see Extensible})
24: *
25: * If the class implements {@see Normalisable}, array keys, parameters and
26: * property names are normalised for comparison.
27: *
28: * Date and time values are converted to {@see DateTimeImmutable} instances
29: * for parameters and declared or "magic" properties that accept
30: * {@see DateTimeImmutable} or are covered by {@see Temporal} (if
31: * implemented by the class).
32: *
33: * If the class implements {@see Treeable} and a parent is given, the
34: * instance is added to the parent as a child.
35: *
36: * @param mixed[] $data
37: * @param static|null $parent
38: * @return static
39: * @throws InvalidDataException if values in `$data` do not satisfy the
40: * constructor or cannot be applied to the class.
41: */
42: public static function construct(
43: array $data,
44: ?object $parent = null,
45: ?ContainerInterface $container = null
46: );
47:
48: /**
49: * Get instances from arrays
50: *
51: * Values in `$data` arrays are applied as per {@see construct()}.
52: *
53: * @template TKey of array-key
54: *
55: * @param iterable<TKey,mixed[]> $data
56: * @param Constructible::* $conformity
57: * @param static|null $parent
58: * @return iterable<TKey,static>
59: * @throws InvalidDataException if values in `$data` arrays do not satisfy
60: * the constructor or cannot be applied to the class.
61: */
62: public static function constructMultiple(
63: iterable $data,
64: int $conformity = Constructible::CONFORMITY_NONE,
65: ?object $parent = null,
66: ?ContainerInterface $container = null
67: ): iterable;
68: }
69: