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 removeAllObjectsOfThe(string $class): MapsObjectsByIdentity |
||
124 | |||
125 | /** @inheritdoc */ |
||
126 | public function idOf(object $object): string |
||
133 | |||
134 | /** @inheritdoc */ |
||
135 | public function classes(): array |
||
139 | |||
140 | public function objects(): array |
||
151 | |||
152 | /** @throws NoSuchObject */ |
||
153 | private function mustHave(string $class, string $id): void |
||
160 | |||
161 | /** @throws AlreadyThere */ |
||
162 | private function mayNotAlreadyHave(string $class, string $id): void |
||
168 | |||
169 | private static function addTo( |
||
177 | } |
||
178 |