Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
19 / 19 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| GetTranslationsFromMenu | |
100.00% |
19 / 19 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| provideStringTranslations | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| collect | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\Cms\Translator; |
| 3 | |
| 4 | use Apie\Cms\MenuStructure\MainMenuBuilder; |
| 5 | use Apie\Common\Concerns\ExpandsTranslationWithBoundedContext; |
| 6 | use Apie\Common\MenuStructure\MenuNode; |
| 7 | use Apie\Common\Translator\TranslationStringProviderInterface; |
| 8 | use Apie\Core\Context\ApieContext; |
| 9 | use Apie\Core\Translator\Lists\TranslationStringSet; |
| 10 | use Apie\Core\Translator\ValueObjects\MenuHeader; |
| 11 | |
| 12 | class GetTranslationsFromMenu implements TranslationStringProviderInterface |
| 13 | { |
| 14 | use ExpandsTranslationWithBoundedContext; |
| 15 | |
| 16 | public function __construct(private readonly MainMenuBuilder $menuBuilder) |
| 17 | { |
| 18 | } |
| 19 | |
| 20 | public function provideStringTranslations(ApieContext $apieContext): TranslationStringSet |
| 21 | { |
| 22 | $root = $this->menuBuilder->buildMenu($apieContext); |
| 23 | /** @var array<int, MenuHeader> $alreadyFound */ |
| 24 | $alreadyFound = []; |
| 25 | return new TranslationStringSet( |
| 26 | iterator_to_array( |
| 27 | $this->iterateOverTranslationWithAllResources( |
| 28 | $apieContext, |
| 29 | $this->collect($root, $alreadyFound), |
| 30 | true |
| 31 | ) |
| 32 | ) |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @param array<int, MenuHeader>& $alreadyFound |
| 38 | * @return array<int, MenuHeader> |
| 39 | */ |
| 40 | private function collect(MenuNode $menuNode, array& $alreadyFound): array |
| 41 | { |
| 42 | $translation = $menuNode->name->withoutBoundedContextId()->withoutResourceIdentifier(); |
| 43 | $alreadyFound[] = $translation; |
| 44 | $alreadyFound[] = $translation->withAuthenticated(true); |
| 45 | $alreadyFound[] = $translation->withAuthenticated(false); |
| 46 | |
| 47 | foreach ($menuNode->children as $child) { |
| 48 | $this->collect($child, $alreadyFound); |
| 49 | } |
| 50 | |
| 51 | return $alreadyFound; |
| 52 | } |
| 53 | } |