| 1: | <?php |
| 2: | |
| 3: | namespace LaravelUi5\Core\Introspection\App; |
| 4: | |
| 5: | use JsonException; |
| 6: | use LaravelUi5\Core\Contracts\Ui5Descriptor; |
| 7: | use LaravelUi5\Core\Contracts\Ui5Source; |
| 8: | use LaravelUi5\Core\Introspection\Ui5Framework; |
| 9: | use LaravelUi5\Core\Introspection\Ui5I18n; |
| 10: | use LaravelUi5\Core\Introspection\Ui5PackageMeta; |
| 11: | |
| 12: | final readonly class Ui5AppSource extends Ui5Source |
| 13: | { |
| 14: | public function __construct( |
| 15: | private string $srcPath, |
| 16: | private Ui5AppDescriptor $descriptor, |
| 17: | private Ui5I18n $i18n, |
| 18: | private bool $isDev, |
| 19: | private ?Ui5PackageMeta $package = null, |
| 20: | private ?Ui5Framework $framework = null, |
| 21: | private ?Ui5Bootstrap $bootstrap = null, |
| 22: | ) |
| 23: | { |
| 24: | } |
| 25: | |
| 26: | |
| 27: | |
| 28: | public function getSourcePath(): string |
| 29: | { |
| 30: | return $this->srcPath; |
| 31: | } |
| 32: | |
| 33: | public function getPackageMeta(): ?Ui5PackageMeta |
| 34: | { |
| 35: | return $this->package; |
| 36: | } |
| 37: | |
| 38: | public function getFramework(): ?Ui5Framework |
| 39: | { |
| 40: | return $this->framework; |
| 41: | } |
| 42: | |
| 43: | public function getDescriptor(): Ui5AppDescriptor |
| 44: | { |
| 45: | return $this->descriptor; |
| 46: | } |
| 47: | |
| 48: | public function getBootstrap(): ?Ui5Bootstrap |
| 49: | { |
| 50: | return $this->bootstrap; |
| 51: | } |
| 52: | |
| 53: | public function getI18n(): Ui5I18n |
| 54: | { |
| 55: | return $this->i18n; |
| 56: | } |
| 57: | |
| 58: | public function isDev(): bool |
| 59: | { |
| 60: | return $this->isDev; |
| 61: | } |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | public static function fromWorkspace(string $path, string $vendor, bool $isDev = false): Ui5AppSource |
| 69: | { |
| 70: | $base = $isDev ? 'webapp' : 'dist'; |
| 71: | |
| 72: | $actualPath = "{$path}/{$base}"; |
| 73: | |
| 74: | $framework = Ui5Framework::fromUi5Yaml($path); |
| 75: | |
| 76: | $package = Ui5PackageMeta::fromPackageJson($path); |
| 77: | |
| 78: | $i18n = Ui5I18n::fromI18nProperties($actualPath); |
| 79: | |
| 80: | $bootstrap = Ui5Bootstrap::fromIndexHtml($actualPath); |
| 81: | |
| 82: | $descriptor = Ui5AppDescriptor::fromManifestJson($actualPath, $i18n, $vendor); |
| 83: | |
| 84: | return new self( |
| 85: | srcPath: $path, |
| 86: | descriptor: $descriptor, |
| 87: | i18n: $i18n, |
| 88: | isDev: $isDev, |
| 89: | package: $package, |
| 90: | framework: $framework, |
| 91: | bootstrap: $bootstrap |
| 92: | ); |
| 93: | } |
| 94: | |
| 95: | |
| 96: | |
| 97: | |
| 98: | public static function fromPackage(string $path, string $vendor): Ui5AppSource |
| 99: | { |
| 100: | $i18n = Ui5I18n::fromI18nProperties($path); |
| 101: | |
| 102: | $descriptor = Ui5AppDescriptor::fromManifestJson($path, $i18n, $vendor); |
| 103: | |
| 104: | return new self( |
| 105: | srcPath: $path, |
| 106: | descriptor: $descriptor, |
| 107: | i18n: $i18n, |
| 108: | isDev: false, |
| 109: | ); |
| 110: | } |
| 111: | } |
| 112: | |