Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
9 / 9 |
CRAP | |
100.00% |
1 / 1 |
| CurrentConfiguration | |
100.00% |
14 / 14 |
|
100.00% |
9 / 9 |
10 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getApieContext | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getBoundedContextHashmap | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSelectedBoundedContextId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSelectedBoundedContext | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| getGlobalUrl | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getContextUrl | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getBrowserTitle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| shouldDisplayBoundedContextSelect | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\HtmlBuilders\Configuration; |
| 3 | |
| 4 | use Apie\Core\BoundedContext\BoundedContext; |
| 5 | use Apie\Core\BoundedContext\BoundedContextHashmap; |
| 6 | use Apie\Core\BoundedContext\BoundedContextId; |
| 7 | use Apie\Core\Context\ApieContext; |
| 8 | |
| 9 | final class CurrentConfiguration |
| 10 | { |
| 11 | private ApieContext $apieContext; |
| 12 | |
| 13 | private ?BoundedContextId $selected; |
| 14 | |
| 15 | /** |
| 16 | * @param array<int|string, mixed> $config |
| 17 | */ |
| 18 | public function __construct( |
| 19 | private readonly array $config, |
| 20 | ApieContext $apieContext, |
| 21 | private BoundedContextHashmap $boundedContextHashmap, |
| 22 | ?BoundedContextId $selected = null |
| 23 | ) { |
| 24 | $this->apieContext = $apieContext->withContext(self::class, $this); |
| 25 | $this->selected = $selected; |
| 26 | } |
| 27 | |
| 28 | public function getApieContext(): ApieContext |
| 29 | { |
| 30 | return $this->apieContext; |
| 31 | } |
| 32 | |
| 33 | public function getBoundedContextHashmap(): BoundedContextHashmap |
| 34 | { |
| 35 | return $this->boundedContextHashmap; |
| 36 | } |
| 37 | |
| 38 | public function getSelectedBoundedContextId(): ?BoundedContextId |
| 39 | { |
| 40 | return $this->selected; |
| 41 | } |
| 42 | |
| 43 | public function getSelectedBoundedContext(): ?BoundedContext |
| 44 | { |
| 45 | if ($this->selected === null) { |
| 46 | return null; |
| 47 | } |
| 48 | return $this->boundedContextHashmap[$this->selected->toNative()] ?? null; |
| 49 | } |
| 50 | |
| 51 | public function getGlobalUrl(string $path): string |
| 52 | { |
| 53 | $url = rtrim($this->config['base_url'] ?? '/', '/'); |
| 54 | return $url . '/' . ltrim($path, '/'); |
| 55 | } |
| 56 | |
| 57 | public function getContextUrl(string $path): string |
| 58 | { |
| 59 | $id = $this->getSelectedBoundedContextId(); |
| 60 | return $this->getGlobalUrl($id . '/' . ltrim($path, '/')); |
| 61 | } |
| 62 | |
| 63 | public function getBrowserTitle(string $pageTitle): string |
| 64 | { |
| 65 | return sprintf((string) ($this->config['head']['title-format'] ?? 'Apie CMS - %s'), $pageTitle); |
| 66 | } |
| 67 | |
| 68 | public function shouldDisplayBoundedContextSelect(): bool |
| 69 | { |
| 70 | return filter_var($this->config['application']['bounded-context-select'] ?? true, FILTER_VALIDATE_BOOL); |
| 71 | } |
| 72 | } |