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