| 1: | <?php |
| 2: | |
| 3: | namespace LaravelUi5\Core\Infrastructure; |
| 4: | |
| 5: | use LaravelUi5\Core\Infrastructure\Contracts\Ui5SourceOverrideStoreInterface; |
| 6: | use LaravelUi5\Core\Infrastructure\Contracts\Ui5SourceStrategyInterface; |
| 7: | use LaravelUi5\Core\Infrastructure\Contracts\Ui5SourceStrategyResolverInterface; |
| 8: | use LogicException; |
| 9: | use ReflectionClass; |
| 10: | |
| 11: | class Ui5SourceStrategyResolver implements Ui5SourceStrategyResolverInterface |
| 12: | { |
| 13: | public function __construct(protected Ui5SourceOverrideStoreInterface $sourceStore) |
| 14: | { |
| 15: | } |
| 16: | |
| 17: | public function resolve(string $moduleClass): Ui5SourceStrategyInterface |
| 18: | { |
| 19: | if ($path = $this->sourceStore->get($moduleClass)) { |
| 20: | return new WorkspaceStrategy($path); |
| 21: | } |
| 22: | |
| 23: | $ref = new ReflectionClass($moduleClass); |
| 24: | |
| 25: | $moduleDir = dirname($ref->getFileName()); |
| 26: | |
| 27: | |
| 28: | |
| 29: | $packagePath = realpath($moduleDir . '/../resources/app'); |
| 30: | if ($packagePath && is_dir($packagePath)) { |
| 31: | return new SelfContainedStrategy($packagePath); |
| 32: | } |
| 33: | |
| 34: | |
| 35: | $packagePath = realpath($moduleDir . '/../resources/dashboard-app'); |
| 36: | if ($packagePath && is_dir($packagePath)) { |
| 37: | return new SelfContainedStrategy($packagePath); |
| 38: | } |
| 39: | |
| 40: | $packagePath = realpath($moduleDir . '/../resources/report-app'); |
| 41: | if ($packagePath && is_dir($packagePath)) { |
| 42: | return new SelfContainedStrategy($packagePath); |
| 43: | } |
| 44: | |
| 45: | |
| 46: | |
| 47: | $packagePath = realpath($moduleDir . '/../resources/ui5'); |
| 48: | |
| 49: | if ($packagePath && is_dir($packagePath)) { |
| 50: | return new PackageStrategy($packagePath); |
| 51: | } |
| 52: | |
| 53: | throw new LogicException( |
| 54: | "Unable to resolve UI5 source path for module [{$moduleClass}] from {$moduleDir}." |
| 55: | ); |
| 56: | } |
| 57: | } |
| 58: | |