1: <?php
2:
3: namespace LaravelUi5\Core\Controllers;
4:
5: use Illuminate\Http\JsonResponse;
6: use Illuminate\Routing\Controller;
7: use LaravelUi5\Core\Contracts\Ui5Context;
8: use LaravelUi5\Core\Services\ExecutableHandler;
9: use LaravelUi5\Core\Ui5\Contracts\Ui5ResourceInterface;
10:
11: /**
12: * Controller for executing UI5 Resources.
13: *
14: * This controller is invoked only for routes that map to UI5 Resources.
15: * The current Ui5Context is provided by middleware and guarantees that
16: * `$context->artifact` is an instance of Ui5ResourceInterface.
17: *
18: * Responsibilities:
19: * - Resolve the ResourceDataProvider from the Resource artifact.
20: * - If the provider implements ParameterizableInterface, inject validated parameters.
21: * - If the provider implements ConfigurableInterface, inject resolved settings.
22: * - Execute the provider and return the result as JSON.
23: *
24: * Notes:
25: * - We assume the artifact in the context is always a Ui5ResourceInterface;
26: * no additional instanceof check is performed here.
27: * - Execution is side-effect free: Resources are read-only endpoints (GET).
28: */
29: class ResourceController extends Controller
30: {
31: public function __invoke(Ui5Context $context, ExecutableHandler $dataProviderHandler): JsonResponse
32: {
33: /** @var Ui5ResourceInterface $resource */
34: $resource = $context->artifact;
35:
36: $provider = $resource->getProvider();
37:
38: $result = $dataProviderHandler->run($provider);
39:
40: return response()->json($result);
41: }
42: }
43: