1: <?php
2:
3: namespace LaravelUi5\Core\Ui5;
4:
5: use LaravelUi5\Core\Enums\ArtifactType;
6: use LaravelUi5\Core\Exceptions\MissingArtifactRootException;
7: use LaravelUi5\Core\Infrastructure\Contracts\Ui5SourceStrategyInterface;
8: use LaravelUi5\Core\Ui5\Contracts\Ui5AppInterface;
9: use LaravelUi5\Core\Ui5\Contracts\Ui5LibraryInterface;
10: use LaravelUi5\Core\Ui5\Contracts\Ui5ModuleInterface;
11:
12: /**
13: * Abstract base class for a UI5 module definition.
14: *
15: * A module represents a self-contained unit of business logic and artifacts,
16: * and is registered via config/ui5.php under the 'modules' key.
17: * Each module is assigned a unique route-level slug used in all URL constructions.
18: *
19: * It may provide one App or one Library (not both), and related sub-artifacts
20: * such as Cards, Reports, Tiles, and Actions. All artifact instances are expected
21: * to be fully constructed and ready to register at boot time.
22: */
23: abstract class AbstractUi5Module implements Ui5ModuleInterface
24: {
25: protected Ui5SourceStrategyInterface $strategy;
26:
27: /**
28: * Create a new UI5 module instance.
29: *
30: * @param Ui5SourceStrategyInterface $strategy Physical path where this module resides in
31: */
32: public function __construct(Ui5SourceStrategyInterface $strategy)
33: {
34: $this->strategy = $strategy;
35: }
36:
37: public function getApp(): ?Ui5AppInterface
38: {
39: return null;
40: }
41:
42: public function hasApp(): bool
43: {
44: return null !== $this->getApp();
45: }
46:
47: public function getLibrary(): ?Ui5LibraryInterface
48: {
49: return null;
50: }
51:
52: public function hasLibrary(): bool
53: {
54: return null !== $this->getLibrary();
55: }
56:
57: public function getArtifactRoot(): Ui5AppInterface|Ui5LibraryInterface
58: {
59: if ($this->hasApp()) {
60: return $this->getApp();
61: }
62:
63: if ($this->hasLibrary()) {
64: return $this->getLibrary();
65: }
66:
67: throw new MissingArtifactRootException(get_class($this));
68: }
69:
70: public function getType(): ArtifactType
71: {
72: return ArtifactType::Module;
73: }
74:
75: public function getSourceStrategy(): Ui5SourceStrategyInterface
76: {
77: return $this->strategy;
78: }
79:
80: public function getAllArtifacts(): array
81: {
82: return [
83: $this->getArtifactRoot(),
84: ...$this->getCards(),
85: ...$this->getKpis(),
86: ...$this->getTiles(),
87: ...$this->getActions(),
88: ...$this->getResources(),
89: ...$this->getReports(),
90: ...$this->getDashboards(),
91: ...$this->getDialogs(),
92: ];
93: }
94: }
95: