Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ResourceCustomActionResourceButtonLabel | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| getFallbackText | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createFromDefinition | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Translator\ValueObjects; |
| 3 | |
| 4 | use Apie\Common\ActionDefinitions\RunResourceMethodDefinition; |
| 5 | use Apie\Core\Attributes\Description; |
| 6 | use Apie\Core\Attributes\ExampleValue; |
| 7 | use Apie\Core\Identifiers\SnakeCaseSlug; |
| 8 | use Apie\Core\Lists\ItemHashmap; |
| 9 | |
| 10 | #[Description('Label shown on button for a domain specific action')] |
| 11 | #[ExampleValue('apie.bounded.test.example.user.action.custom.1234.deactivate.label.authenticated')] |
| 12 | class ResourceCustomActionResourceButtonLabel extends AbstractTranslation |
| 13 | { |
| 14 | protected const MIDDLE_REGEX = 'action\.custom\.:id\.:action\.label'; |
| 15 | |
| 16 | public function getFallbackText(): string |
| 17 | { |
| 18 | return ucfirst(SnakeCaseSlug::fromText($this->getPlaceholders()['action'] ?? 'action')->humanize()); |
| 19 | } |
| 20 | |
| 21 | public static function createFromDefinition(RunResourceMethodDefinition $actionDefinition, ?bool $authenticated): static |
| 22 | { |
| 23 | $action = SnakeCaseSlug::fromClass($actionDefinition->getMethod()); |
| 24 | return new static( |
| 25 | new TranslationStringPrefix( |
| 26 | $actionDefinition->getBoundedContextId(), |
| 27 | SnakeCaseSlug::fromClass($actionDefinition->getResourceName()) |
| 28 | ), |
| 29 | 'action.custom.:id.' . $action . '.label', |
| 30 | new TranslationStringSuffix(null, $authenticated), |
| 31 | new ItemHashmap(['action' => $action]) |
| 32 | ); |
| 33 | } |
| 34 | } |