1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace LaravelUi5\OData\Service\Resolver;
6:
7: use Illuminate\Database\Query\Builder;
8: use Illuminate\Support\Facades\DB;
9: use LaravelUi5\OData\Driver\Sql\SqlEntitySetResolver;
10: use LaravelUi5\OData\Service\Contracts\EntitySetResolverInterface;
11: use LaravelUi5\OData\Service\Contracts\EntitySetSourceInterface;
12: use LaravelUi5\OData\Service\Contracts\ResolverBindingInterface;
13:
14: /**
15: * Serializable binding for a table-or-view-backed entity set.
16: *
17: * Stores the table/view name and optional connection. For sources that
18: * need implicit filters or dependency injection, use SqlSourceBinding
19: * with an EntitySetSourceInterface class instead.
20: */
21: final readonly class SqlBinding implements ResolverBindingInterface, EntitySetSourceInterface
22: {
23: public function __construct(
24: public string $table,
25: public ?string $connection = null,
26: ) {}
27:
28: public function query(): Builder
29: {
30: return DB::connection($this->connection)->table($this->table);
31: }
32:
33: public function createResolver(): EntitySetResolverInterface
34: {
35: return new SqlEntitySetResolver($this);
36: }
37: }
38: