1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace LaravelUi5\OData\Service\Resolver;
6:
7: use LaravelUi5\OData\Service\Contracts\ResolverBindingInterface;
8: use LaravelUi5\OData\Service\Contracts\RuntimeSchemaBuilderInterface;
9:
10: /**
11: * Frozen, serializable registry of entity set resolver bindings.
12: *
13: * On both cold and warm boot, the ResolverMap drives resolver creation:
14: * it iterates its bindings, calls createResolver() on each, and binds the
15: * result to the corresponding entity set in the RuntimeSchemaBuilder.
16: */
17: final readonly class ResolverMap
18: {
19: /**
20: * @param array<string, ResolverBindingInterface> $bindings entitySetName => binding
21: */
22: public function __construct(private array $bindings) {}
23:
24: /**
25: * Create resolvers and bind them to entity sets in the runtime builder.
26: */
27: public function applyTo(RuntimeSchemaBuilderInterface $builder): void
28: {
29: $container = $builder->getEdmx()->getEntityContainer();
30:
31: foreach ($this->bindings as $entitySetName => $binding) {
32: $set = $container->getEntitySet($entitySetName);
33: if ($set !== null) {
34: $builder->bindEntitySet($set, $binding->createResolver());
35: }
36: }
37: }
38:
39: /**
40: * @return array<string, ResolverBindingInterface>
41: */
42: public function getBindings(): array
43: {
44: return $this->bindings;
45: }
46: }
47: