Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ResourceCustomGlobalActionResourceButtonLabel
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 getFallbackText
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 createFromDefinition
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2namespace Apie\Core\Translator\ValueObjects;
3
4use Apie\Common\ActionDefinitions\RunResourceMethodDefinition;
5use Apie\Core\Attributes\Description;
6use Apie\Core\Attributes\ExampleValue;
7use Apie\Core\Identifiers\SnakeCaseSlug;
8use Apie\Core\Lists\ItemHashmap;
9
10#[Description('Label shown on button for a domain specific action')]
11#[ExampleValue('apie.bounded.test.example.user.action.global.create_admin.label.authenticated')]
12class ResourceCustomGlobalActionResourceButtonLabel extends AbstractTranslation
13{
14    protected const MIDDLE_REGEX = 'action\.global\.:action\.label';
15
16    public function getFallbackText(): string
17    {
18        return ucfirst(SnakeCaseSlug::fromText($this->getPlaceholders()['action'] ?? 'action'));
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.global.' . $action . '.label',
30            new TranslationStringSuffix(null, $authenticated),
31            new ItemHashmap(['action' => $action])
32        );
33    }
34}