|
13 | 13 | use LaravelUi5\Core\Ui5\Contracts\ReportActionInterface; |
14 | 14 | use LaravelUi5\Core\Ui5\Contracts\SluggableInterface; |
15 | 15 | use LaravelUi5\Core\Ui5\Contracts\Ui5ActionInterface; |
| 16 | +use LaravelUi5\Core\Ui5\Contracts\Ui5AppInterface; |
16 | 17 | use LaravelUi5\Core\Ui5\Contracts\Ui5ArtifactInterface; |
| 18 | +use LaravelUi5\Core\Ui5\Contracts\Ui5CardInterface; |
| 19 | +use LaravelUi5\Core\Ui5\Contracts\Ui5DashboardInterface; |
| 20 | +use LaravelUi5\Core\Ui5\Contracts\Ui5DialogInterface; |
| 21 | +use LaravelUi5\Core\Ui5\Contracts\Ui5KpiInterface; |
17 | 22 | use LaravelUi5\Core\Ui5\Contracts\Ui5ModuleInterface; |
18 | 23 | use LaravelUi5\Core\Ui5\Contracts\Ui5RegistryInterface; |
19 | 24 | use LaravelUi5\Core\Ui5\Contracts\Ui5ReportInterface; |
| 25 | +use LaravelUi5\Core\Ui5\Contracts\Ui5ResourceInterface; |
| 26 | +use LaravelUi5\Core\Ui5\Contracts\Ui5TileInterface; |
20 | 27 | use LogicException; |
21 | 28 | use ReflectionClass; |
22 | 29 | use ReflectionException; |
@@ -183,30 +190,47 @@ protected function discoverAbilities(Ui5ArtifactInterface|ReportActionInterface |
183 | 190 | /** @var Ability $ability */ |
184 | 191 | $ability = $attributes[0]->newInstance(); |
185 | 192 |
|
186 | | - if ($ability->type === AbilityType::Use) { |
| 193 | + if ($ability->type->shouldBeInManifest()) { |
187 | 194 | throw new LogicException(sprintf( |
188 | | - 'Invalid ability declaration: [%s] uses type [Use], which is reserved for UI visibility. Move this definition to your manifest.json file.', |
189 | | - $ability->name |
| 195 | + 'AbilityType::%s for ability %s cannot be declared in backend artifacts (%s). Move this definition to your manifest.json file.', |
| 196 | + $ability->name, |
| 197 | + $ability->type->name, |
| 198 | + get_class($artifact) |
190 | 199 | )); |
191 | 200 | } |
192 | 201 |
|
193 | | - if ($ability->type === AbilityType::Act && !($artifact instanceof Ui5ActionInterface || $artifact instanceof ReportActionInterface)) { |
| 202 | + if ($ability->type->isAct() && !($artifact instanceof Ui5ActionInterface || $artifact instanceof ReportActionInterface)) { |
194 | 203 | throw new LogicException(sprintf( |
195 | | - 'Ability [%s] of type [Act] must be declared on an executable artifact, found on [%s].', |
| 204 | + 'AbilityType::Act for ability %s must be declared on an executable artifact, found on (%s).', |
196 | 205 | $ability->name, |
197 | 206 | get_class($artifact) |
198 | 207 | )); |
199 | 208 | } |
200 | 209 |
|
201 | | - if (array_key_exists($ability->name, $this->abilities[$namespace] ?? [])) { |
| 210 | + if ($ability->type->isAccess() && !( |
| 211 | + $artifact instanceof Ui5AppInterface |
| 212 | + || $artifact instanceof Ui5CardInterface |
| 213 | + || $artifact instanceof Ui5ReportInterface |
| 214 | + || $artifact instanceof Ui5TileInterface |
| 215 | + || $artifact instanceof Ui5KpiInterface |
| 216 | + || $artifact instanceof Ui5DashboardInterface |
| 217 | + || $artifact instanceof Ui5ResourceInterface |
| 218 | + || $artifact instanceof Ui5DialogInterface |
| 219 | + )) { |
| 220 | + throw new LogicException( |
| 221 | + sprintf('AbilityType::Access is only valid for entry-level artifacts (%s)', get_class($artifact)) |
| 222 | + ); |
| 223 | + } |
| 224 | + |
| 225 | + if (array_key_exists($ability->name, $this->abilities[$namespace][$ability->type->label()] ?? [])) { |
202 | 226 | throw new LogicException(sprintf( |
203 | 227 | 'Duplicate ability [%s] found on [%s].', |
204 | 228 | $ability->name, |
205 | 229 | get_class($artifact) |
206 | 230 | )); |
207 | 231 | } |
208 | 232 |
|
209 | | - $this->abilities[$namespace][$ability->name] = [ |
| 233 | + $this->abilities[$namespace][$ability->type->label()][$ability->name] = [ |
210 | 234 | 'type' => $ability->type->name, |
211 | 235 | 'role' => $ability->role, |
212 | 236 | 'note' => $ability->note, |
@@ -429,14 +453,37 @@ public function roles(): array |
429 | 453 | return $this->roles; |
430 | 454 | } |
431 | 455 |
|
432 | | - public function abilities(): array |
| 456 | + public function abilities(?string $namespace = null, ?ArtifactType $type = null): array |
433 | 457 | { |
434 | | - return $this->abilities; |
| 458 | + if ($namespace === null) { |
| 459 | + if ($type === null) { |
| 460 | + return $this->abilities; |
| 461 | + } |
| 462 | + |
| 463 | + $result = []; |
| 464 | + foreach ($this->abilities as $ns => $types) { |
| 465 | + if (isset($types[$type->label()])) { |
| 466 | + $result[$ns] = $types[$type->label()]; |
| 467 | + } |
| 468 | + } |
| 469 | + |
| 470 | + return $result; |
| 471 | + } |
| 472 | + |
| 473 | + if ($type === null) { |
| 474 | + return $this->abilities[$namespace] ?? []; |
| 475 | + } |
| 476 | + |
| 477 | + return $this->abilities[$namespace][$type->label()] ?? []; |
435 | 478 | } |
436 | 479 |
|
437 | | - public function settings(): array |
| 480 | + public function settings(?string $namespace = null): array |
438 | 481 | { |
439 | | - return $this->settings; |
| 482 | + if (null === $namespace) { |
| 483 | + return $this->settings; |
| 484 | + } |
| 485 | + |
| 486 | + return $this->settings[$namespace] ?? []; |
440 | 487 | } |
441 | 488 |
|
442 | 489 | public function objects(): array |
|
0 commit comments