Passed
Push — master ( cca6b1...f7b887 )
by Alexander
10:54
created

LayoutViewInjection   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLayoutParameters() 0 6 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\ViewInjection;
6
7
use Yiisoft\Router\UrlMatcherInterface;
8
use Yiisoft\Yii\View\LayoutParametersInjectionInterface;
9
use Yiisoft\Yii\Web\User\User;
10
11
class LayoutViewInjection implements LayoutParametersInjectionInterface
12
{
13
    private User $user;
14
    private UrlMatcherInterface $urlMatcher;
15
16
    public function __construct(
17
        User $user,
18
        UrlMatcherInterface $urlMatcher
19
    ) {
20
        $this->user = $user;
21
        $this->urlMatcher = $urlMatcher;
22
    }
23
24
    public function getLayoutParameters(): array
25
    {
26
        return [
27
            'user' => $this->user->getIdentity(),
28
            'currentUrl' => (string)$this->urlMatcher->getLastMatchedRequest()->getUri(),
29
            'brandLabel' => 'Yii Demo',
30
        ];
31
    }
32
}
33