| 1: | <?php |
| 2: | |
| 3: | namespace LaravelUi5\Core\Services; |
| 4: | |
| 5: | use Illuminate\Http\Request; |
| 6: | use LaravelUi5\Core\Contracts\Ui5ArtifactResolverInterface; |
| 7: | use LaravelUi5\Core\Enums\ArtifactType; |
| 8: | use LaravelUi5\Core\Ui5\Contracts\Ui5ArtifactInterface; |
| 9: | use LaravelUi5\Core\Ui5\Contracts\Ui5RegistryInterface; |
| 10: | use LaravelUi5\Core\Ui5CoreServiceProvider; |
| 11: | |
| 12: | readonly class PathBasedArtifactResolver implements Ui5ArtifactResolverInterface |
| 13: | { |
| 14: | |
| 15: | public function __construct( |
| 16: | private Ui5RegistryInterface $registry |
| 17: | ) |
| 18: | { |
| 19: | } |
| 20: | |
| 21: | public function resolve(Request $request): ?Ui5ArtifactInterface |
| 22: | { |
| 23: | $path = $request->path(); |
| 24: | |
| 25: | if (!str_starts_with($path, Ui5CoreServiceProvider::UI5_ROUTE_PREFIX)) { |
| 26: | return null; |
| 27: | } |
| 28: | $relative = trim(substr($path, strlen(Ui5CoreServiceProvider::UI5_ROUTE_PREFIX)), '/'); |
| 29: | |
| 30: | $urlKey = ArtifactType::urlKeyFromPath($relative); |
| 31: | |
| 32: | if (is_null($urlKey)) { |
| 33: | return null; |
| 34: | } |
| 35: | |
| 36: | return $this->registry->fromSlug($urlKey); |
| 37: | } |
| 38: | } |
| 39: | |