1: <?php
2:
3: namespace LaravelUi5\Core\Introspection\Library;
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 Ui5LibrarySource extends Ui5Source
13: {
14: public function __construct(
15: private string $srcPath,
16: private Ui5LibraryDescriptor $descriptor,
17: private Ui5I18n $i18n,
18: private ?Ui5PackageMeta $package = null,
19: private ?Ui5Framework $framework = null,
20: )
21: {
22: }
23:
24: /* -- Introspection API ------------------------------------------------ */
25:
26: public function getSourcePath(): string
27: {
28: return $this->srcPath;
29: }
30:
31: public function getPackageMeta(): ?Ui5PackageMeta
32: {
33: return $this->package;
34: }
35:
36: public function getFramework(): ?Ui5Framework
37: {
38: return $this->framework;
39: }
40:
41: public function getDescriptor(): Ui5LibraryDescriptor
42: {
43: return $this->descriptor;
44: }
45:
46: public function getI18n(): Ui5I18n
47: {
48: return $this->i18n;
49: }
50:
51: /* -- Factory ---------------------------------------------------------- */
52:
53: /**
54: * @throws JsonException
55: */
56: public static function fromWorkspace(string $path): self
57: {
58: $framework = Ui5Framework::fromUi5Yaml($path);
59:
60: $package = Ui5PackageMeta::fromPackageJson($path);
61:
62: $library = Ui5LibraryDescriptor::fromLibraryXml($path, $framework->getNamespace(), $package->getBuilder());
63:
64: $i18n = Ui5I18n::fromMessageBundles($path, $framework->getNamespace());
65:
66: return new self(
67: srcPath: $path,
68: descriptor: $library,
69: i18n: $i18n,
70: package: $package,
71: framework: $framework
72: );
73: }
74:
75: /**
76: * @throws JsonException
77: */
78: public static function fromPackage(string $path, string $vendor): self
79: {
80: $library = Ui5LibraryDescriptor::fromLibraryManifest($path, $vendor);
81:
82: $i18n = Ui5I18n::fromBundles($path);
83:
84: return new self(
85: srcPath: $path,
86: descriptor: $library,
87: i18n: $i18n,
88: );
89: }
90: }
91: