| 1: | <?php |
| 2: | |
| 3: | namespace LaravelUi5\Core\View\Components; |
| 4: | |
| 5: | use Illuminate\View\Component; |
| 6: | use LaravelUi5\Core\Contracts\AuthServiceInterface; |
| 7: | use LaravelUi5\Core\Contracts\Ui5Context; |
| 8: | use LaravelUi5\Core\Ui5\Contracts\ResolvableInterface; |
| 9: | use LaravelUi5\Core\Ui5\Contracts\Ui5RuntimeInterface; |
| 10: | use Psr\Container\ContainerExceptionInterface; |
| 11: | use Psr\Container\NotFoundExceptionInterface; |
| 12: | |
| 13: | class Ui5Element extends Component |
| 14: | { |
| 15: | |
| 16: | public function __construct(public string $id) |
| 17: | { |
| 18: | } |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | public function render(): string |
| 25: | { |
| 26: | $artifact = app(Ui5RuntimeInterface::class)->get($this->id); |
| 27: | |
| 28: | if ($artifact instanceof ResolvableInterface) { |
| 29: | if (app(AuthServiceInterface::class)->authorize( |
| 30: | $artifact->getNamespace(), |
| 31: | app(Ui5Context::class) |
| 32: | )) { |
| 33: | return $artifact->resolve(); |
| 34: | } |
| 35: | } |
| 36: | |
| 37: | return ''; |
| 38: | } |
| 39: | } |
| 40: | |