1 | <?php |
||
20 | final class IdentityMap implements MapsObjectsByIdentity |
||
21 | { |
||
22 | private $objectWith; |
||
23 | private $entityIdFor; |
||
24 | private $objects; |
||
25 | |||
26 | private function __construct(array $objectsByClassAndId, array $idsByObject) |
||
31 | |||
32 | /** |
||
33 | * Produces a new identity map that contains the objects. |
||
34 | * |
||
35 | * @param object[] $theseObjects The objects to add, as [id => object] |
||
36 | * @return MapsObjectsByIdentity The map of objects. |
||
37 | */ |
||
38 | public static function with(array $theseObjects): MapsObjectsByIdentity |
||
48 | |||
49 | /** |
||
50 | * Produces an empty identity map. |
||
51 | * |
||
52 | * @return MapsObjectsByIdentity The empty map of objects. |
||
53 | */ |
||
54 | public static function startEmpty(): MapsObjectsByIdentity |
||
58 | |||
59 | /** @inheritdoc */ |
||
60 | public function has(string $class, string $id): bool |
||
64 | |||
65 | /** @inheritdoc */ |
||
66 | public function hasThe(object $object): bool |
||
70 | |||
71 | /** @inheritdoc */ |
||
72 | public function get(string $class, string $id): object |
||
77 | |||
78 | /** @inheritdoc */ |
||
79 | public function add(string $id, object $object): MapsObjectsByIdentity |
||
89 | |||
90 | /** @inheritdoc */ |
||
91 | public function remove(string $class, string $id): MapsObjectsByIdentity |
||
102 | |||
103 | /** @inheritdoc */ |
||
104 | public function removeThe(object $object): MapsObjectsByIdentity |
||
108 | |||
109 | /** @inheritdoc */ |
||
110 | public function idOf(object $object): string |
||
117 | |||
118 | public function objects(): array |
||
129 | |||
130 | /** @throws NoSuchObject */ |
||
131 | private function mustHave(string $class, string $id): void |
||
138 | |||
139 | /** @throws AlreadyThere */ |
||
140 | private function mayNotAlreadyHave(string $class, string $id): void |
||
146 | |||
147 | private static function addTo( |
||
155 | } |
||
156 |