|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
3
|
|
|
namespace Jaxon\Request\Factory\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 Jaxon\Request\Handler\Psr\PsrAjaxMiddleware; |
|
19
|
|
|
use Jaxon\Request\Handler\Psr\PsrConfigMiddleware; |
|
20
|
|
|
use Jaxon\Request\Handler\Psr\PsrRequestHandler; |
|
21
|
|
|
use Psr\Container\ContainerInterface; |
|
22
|
|
|
use Psr\Log\LoggerInterface; |
|
23
|
|
|
|
|
24
|
|
|
use Closure; |
|
25
|
|
|
|
|
26
|
|
|
class PsrFactory |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* The container |
|
30
|
|
|
* |
|
31
|
|
|
* @var Container |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $di; |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* The constructor |
|
37
|
|
|
* |
|
38
|
|
|
* @param Container $di |
|
|
|
|
|
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct(Container $di) |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$this->di = $di; |
|
43
|
|
|
} |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Set the logger |
|
47
|
|
|
* |
|
48
|
|
|
* @param LoggerInterface $xLogger |
|
|
|
|
|
|
49
|
|
|
* |
|
50
|
|
|
* @return $this |
|
51
|
|
|
*/ |
|
52
|
|
|
public function logger(LoggerInterface $xLogger): PsrFactory |
|
53
|
|
|
{ |
|
54
|
|
|
$this->di->setLogger($xLogger); |
|
55
|
|
|
return $this; |
|
56
|
|
|
} |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Set the container |
|
60
|
|
|
* |
|
61
|
|
|
* @param ContainerInterface $xContainer |
|
|
|
|
|
|
62
|
|
|
* |
|
63
|
|
|
* @return $this |
|
64
|
|
|
*/ |
|
65
|
|
|
public function container(ContainerInterface $xContainer): PsrFactory |
|
66
|
|
|
{ |
|
67
|
|
|
$this->di->setContainer($xContainer); |
|
68
|
|
|
return $this; |
|
69
|
|
|
} |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Add a view renderer with an id |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $sRenderer The renderer name |
|
|
|
|
|
|
75
|
|
|
* @param string $sExtension The extension to append to template names |
|
|
|
|
|
|
76
|
|
|
* @param Closure $xClosure A closure to create the view instance |
|
|
|
|
|
|
77
|
|
|
* |
|
78
|
|
|
* @return void |
|
79
|
|
|
*/ |
|
80
|
|
|
public function view(string $sRenderer, string $sExtension, Closure $xClosure) |
|
81
|
|
|
{ |
|
82
|
|
|
$xViewRenderer = $this->di->getViewRenderer(); |
|
83
|
|
|
$xViewRenderer->addNamespace('default', '', $sExtension, $sRenderer); |
|
84
|
|
|
$xViewRenderer->addRenderer($sRenderer, $xClosure); |
|
85
|
|
|
} |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Get the Jaxon ajax PSR request handler |
|
89
|
|
|
* |
|
90
|
|
|
* @return PsrRequestHandler |
|
91
|
|
|
*/ |
|
92
|
|
|
public function handler(): PsrRequestHandler |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->di->getPsrRequestHandler(); |
|
95
|
|
|
} |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Get the Jaxon config PSR middleware |
|
99
|
|
|
* |
|
100
|
|
|
* @param string $sConfigFile |
|
|
|
|
|
|
101
|
|
|
* |
|
102
|
|
|
* @return PsrConfigMiddleware |
|
103
|
|
|
*/ |
|
104
|
|
|
public function config(string $sConfigFile): PsrConfigMiddleware |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->di->getPsrConfigMiddleware($sConfigFile); |
|
107
|
|
|
} |
|
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Get the Jaxon ajax PSR middleware |
|
111
|
|
|
* |
|
112
|
|
|
* @return PsrAjaxMiddleware |
|
113
|
|
|
*/ |
|
114
|
|
|
public function ajax(): PsrAjaxMiddleware |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->di->getPsrAjaxMiddleware(); |
|
117
|
|
|
} |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|