Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ResourceAddResourceHeader | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| getFallbackText | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| createFromDefinition | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Translator\ValueObjects; |
| 3 | |
| 4 | use Apie\Common\ActionDefinitions\CreateResourceActionDefinition; |
| 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('Header shown on add resource form')] |
| 11 | #[ExampleValue('apie.bounded.test.example.user.action.add.header.authenticated')] |
| 12 | class ResourceAddResourceHeader extends AbstractTranslation |
| 13 | { |
| 14 | protected const MIDDLE_REGEX = 'action\.add\.header'; |
| 15 | |
| 16 | public function getFallbackText(): string |
| 17 | { |
| 18 | $id = $this->prefix->getResourceIdentifier(); |
| 19 | if ($id) { |
| 20 | return 'Create ' . $id->humanize(); |
| 21 | } |
| 22 | return 'Create'; |
| 23 | } |
| 24 | |
| 25 | public static function createFromDefinition(CreateResourceActionDefinition $actionDefinition, ?bool $authenticated): static |
| 26 | { |
| 27 | return new static( |
| 28 | new TranslationStringPrefix( |
| 29 | $actionDefinition->getBoundedContextId(), |
| 30 | SnakeCaseSlug::fromClass($actionDefinition->getResourceName()) |
| 31 | ), |
| 32 | 'action.add.header', |
| 33 | new TranslationStringSuffix(null, $authenticated), |
| 34 | new ItemHashmap() |
| 35 | ); |
| 36 | } |
| 37 | } |