1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace Jaxon\Request\Handler\Psr; |
4
|
|
|
|
5
|
|
|
/** |
|
|
|
|
6
|
|
|
* PsrFactory.php |
7
|
|
|
* |
8
|
|
|
* A factory for PSR. |
9
|
|
|
* |
10
|
|
|
* @package jaxon-core |
11
|
|
|
* @author Thierry Feuzeu |
12
|
|
|
* @copyright 2022 Thierry Feuzeu <[email protected]> |
13
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License |
14
|
|
|
* @link https://github.com/jaxon-php/jaxon-core |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
use Jaxon\Di\Container; |
18
|
|
|
use Psr\Container\ContainerInterface; |
19
|
|
|
use Psr\Log\LoggerInterface; |
20
|
|
|
|
21
|
|
|
use Closure; |
22
|
|
|
|
23
|
|
|
class PsrFactory |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* The container |
27
|
|
|
* |
28
|
|
|
* @var Container |
29
|
|
|
*/ |
30
|
|
|
protected $di; |
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The constructor |
34
|
|
|
* |
35
|
|
|
* @param Container $di |
|
|
|
|
36
|
|
|
*/ |
37
|
|
|
public function __construct(Container $di) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$this->di = $di; |
40
|
|
|
} |
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Set the logger |
44
|
|
|
* |
45
|
|
|
* @param LoggerInterface $xLogger |
|
|
|
|
46
|
|
|
* |
47
|
|
|
* @return $this |
48
|
|
|
*/ |
49
|
|
|
public function logger(LoggerInterface $xLogger): PsrFactory |
50
|
|
|
{ |
51
|
|
|
$this->di->setLogger($xLogger); |
52
|
|
|
return $this; |
53
|
|
|
} |
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Set the container |
57
|
|
|
* |
58
|
|
|
* @param ContainerInterface $xContainer |
|
|
|
|
59
|
|
|
* |
60
|
|
|
* @return $this |
61
|
|
|
*/ |
62
|
|
|
public function container(ContainerInterface $xContainer): PsrFactory |
63
|
|
|
{ |
64
|
|
|
$this->di->setContainer($xContainer); |
65
|
|
|
return $this; |
66
|
|
|
} |
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Add a view renderer with an id |
70
|
|
|
* |
71
|
|
|
* @param string $sRenderer The renderer name |
|
|
|
|
72
|
|
|
* @param string $sExtension The extension to append to template names |
|
|
|
|
73
|
|
|
* @param Closure $xClosure A closure to create the view instance |
|
|
|
|
74
|
|
|
* |
75
|
|
|
* @return $this |
76
|
|
|
*/ |
77
|
|
|
public function view(string $sRenderer, string $sExtension, Closure $xClosure): PsrFactory |
78
|
|
|
{ |
79
|
|
|
$this->di->getViewRenderer()->setDefaultRenderer($sRenderer, $sExtension, $xClosure); |
80
|
|
|
return $this; |
81
|
|
|
} |
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get the Jaxon ajax PSR request handler |
85
|
|
|
* |
86
|
|
|
* @return PsrRequestHandler |
87
|
|
|
*/ |
88
|
|
|
public function handler(): PsrRequestHandler |
89
|
|
|
{ |
90
|
|
|
return $this->di->getPsrRequestHandler(); |
91
|
|
|
} |
|
|
|
|
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get the Jaxon config PSR middleware |
95
|
|
|
* |
96
|
|
|
* @param string $sConfigFile |
|
|
|
|
97
|
|
|
* |
98
|
|
|
* @return PsrConfigMiddleware |
99
|
|
|
*/ |
100
|
|
|
public function config(string $sConfigFile): PsrConfigMiddleware |
101
|
|
|
{ |
102
|
|
|
return $this->di->getPsrConfigMiddleware($sConfigFile); |
103
|
|
|
} |
|
|
|
|
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get the Jaxon ajax PSR middleware |
107
|
|
|
* |
108
|
|
|
* @return PsrAjaxMiddleware |
109
|
|
|
*/ |
110
|
|
|
public function ajax(): PsrAjaxMiddleware |
111
|
|
|
{ |
112
|
|
|
return $this->di->getPsrAjaxMiddleware(); |
113
|
|
|
} |
|
|
|
|
114
|
|
|
} |
115
|
|
|
|