1: <?php
2:
3: namespace LaravelUi5\Core\Introspection;
4:
5: use Illuminate\Support\Facades\File;
6: use LogicException;
7: use Symfony\Component\Yaml\Yaml;
8:
9: final readonly class Ui5Framework
10: {
11: public function __construct(
12: private string $name,
13: private string $version,
14: private string $namespace,
15: )
16: {
17: }
18:
19: /* -- API -------------------------------------------------------------- */
20:
21: public function getName(): string
22: {
23: return $this->name;
24: }
25:
26: public function getVersion(): string
27: {
28: return $this->version;
29: }
30:
31: public function getNamespace(): string
32: {
33: return $this->namespace;
34: }
35:
36: /* -- Factory ---------------------------------------------------------- */
37:
38: public static function fromUi5Yaml(string $path): self
39: {
40: $ui5Yaml = $path . '/ui5.yaml';
41:
42: if (!File::exists($ui5Yaml)) {
43: throw new LogicException("ui5.yaml not found in {$path}");
44: }
45:
46: $yaml = Yaml::parseFile($ui5Yaml);
47:
48: $namespace = $yaml['metadata']['name'] ?? null;
49: if (!$namespace) {
50: throw new LogicException("Missing metadata.name in ui5.yaml");
51: }
52:
53: return new self(
54: name: $yaml['framework']['name'] ?? 'OpenUI5',
55: version: $yaml['framework']['version'] ?? '1.136.0',
56: namespace: $namespace,
57: );
58: }
59: }
60: