1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of template |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Slick\Template\Extension; |
13
|
|
|
|
14
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
15
|
|
|
use Slick\Configuration\ConfigurationInterface; |
16
|
|
|
use Slick\Configuration\Driver\Environment; |
17
|
|
|
use Slick\WebStack\Domain\Security\SecurityAuthenticatorInterface; |
18
|
|
|
use Slick\WebStack\Domain\Security\UserInterface; |
19
|
|
|
use Slick\WebStack\Infrastructure\Http\FlashMessageStorage; |
20
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* SlickApp |
24
|
|
|
* |
25
|
|
|
* @package Slick\Template\Extension |
26
|
|
|
*/ |
27
|
|
|
class SlickApp |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Creates a SlickApp |
31
|
|
|
* |
32
|
|
|
* @param SecurityAuthenticatorInterface|null $authenticator |
33
|
|
|
* @param ServerRequestInterface|null $request |
34
|
|
|
* @param ConfigurationInterface|null $settings |
35
|
|
|
* @param UrlGeneratorInterface|null $generator |
36
|
|
|
* @param FlashMessageStorage|null $flash |
37
|
|
|
*/ |
38
|
|
|
public function __construct( |
39
|
|
|
private readonly ?SecurityAuthenticatorInterface $authenticator = null, |
40
|
|
|
private readonly ?ServerRequestInterface $request = null, |
41
|
|
|
private readonly ?ConfigurationInterface $settings = null, |
42
|
|
|
private readonly ?UrlGeneratorInterface $generator = null, |
43
|
|
|
private readonly ?FlashMessageStorage $flash = null |
44
|
|
|
) { |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Retrieves the authenticated user, if available. |
49
|
|
|
* |
50
|
|
|
* @return UserInterface|null The authenticated user, or null if not authenticated. |
51
|
|
|
*/ |
52
|
|
|
public function user(): ?UserInterface |
53
|
|
|
{ |
54
|
|
|
if ($this->authenticator && $this->authenticator->enabled()) { |
55
|
|
|
return $this->authenticator->user(); |
56
|
|
|
} |
57
|
|
|
return null; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Retrieve the server request. |
62
|
|
|
* |
63
|
|
|
* @return ServerRequestInterface|null The server request object, or null if not set. |
64
|
|
|
*/ |
65
|
|
|
public function request(): ?ServerRequestInterface |
66
|
|
|
{ |
67
|
|
|
return $this->request; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function settings(): ConfigurationInterface |
71
|
|
|
{ |
72
|
|
|
if (!$this->settings) { |
73
|
|
|
return new Environment(); |
74
|
|
|
} |
75
|
|
|
return $this->settings; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function generator(): ?UrlGeneratorInterface |
79
|
|
|
{ |
80
|
|
|
return $this->generator; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function flash(): ?FlashMessageStorage |
84
|
|
|
{ |
85
|
|
|
return $this->flash; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|