1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace LaravelUi5\OData\Service\Contracts;
6:
7: use Illuminate\Database\Query\Builder;
8:
9: /**
10: * Formal contract for SQL-backed entity set data sources.
11: *
12: * Implementations provide the base query for an entity set, including any
13: * implicit filters (tenant scoping, user permissions, etc.). OData system
14: * query options ($filter, $orderby, $top, $skip) are applied on top by the
15: * resolver — they never override the base query's constraints.
16: *
17: * Implementations are resolved from the Laravel container so that dependencies
18: * (e.g., the current tenant or authenticated user) are injected automatically.
19: *
20: * Example:
21: *
22: * final readonly class PartnerValueHelpSource implements EntitySetSourceInterface
23: * {
24: * public function __construct(private TenantContext $tenant) {}
25: *
26: * public function query(): Builder
27: * {
28: * return DB::table('partner_value_help')
29: * ->where('tenant_id', $this->tenant->id);
30: * }
31: * }
32: */
33: interface EntitySetSourceInterface
34: {
35: /**
36: * Return the base query for this entity set.
37: *
38: * The returned builder must be a fresh instance on each call — it will be
39: * mutated by the resolver when applying OData query options.
40: */
41: public function query(): Builder;
42: }
43: