Passed
Push — master ( 4bccec...259a7c )
by David
01:44
created

StaticRegistry::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace TheCodingMachine\CMS\StaticRegistry\Registry;
5
6
7
use Psr\Http\Message\ServerRequestInterface;
8
use TheCodingMachine\CMS\Block\Block;
9
use TheCodingMachine\CMS\Block\BlockInterface;
10
use TheCodingMachine\CMS\Page\PageRegistryInterface;
11
12
class StaticRegistry implements PageRegistryInterface
13
{
14
    /**
15
     * @var PageRegistry
16
     */
17
    private $pageRegistry;
18
    /**
19
     * @var ThemeRegistry
20
     */
21
    private $themeRegistry;
22
23
    public function __construct(PageRegistry $pageRegistry, ThemeRegistry $themeRegistry)
24
    {
25
        $this->pageRegistry = $pageRegistry;
26
        $this->themeRegistry = $themeRegistry;
27
    }
28
29
    public function getPage(ServerRequestInterface $request): ?BlockInterface
30
    {
31
        $uri = $request->getUri();
32
        $domain = $uri->getHost();
33
        $url = $uri->getPath();
34
35
        $page = $this->pageRegistry->getPage($url, $domain);
36
37
        $block = new Block($this->themeRegistry->getThemeDescriptor($page->getTheme()), [
38
            'content' => [ $page->getContent() ]
39
        ]);
40
41
        return $block;
42
    }
43
}
44