1 | <?php |
||
10 | class TwigRequestHandler implements RequestHandlerInterface |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * @var ResponseFactoryInterface |
||
15 | */ |
||
16 | public $response_factory; |
||
17 | |||
18 | |||
19 | /** |
||
20 | * @var TwigEnvironment|null |
||
21 | */ |
||
22 | public $twig; |
||
23 | |||
24 | |||
25 | /** |
||
26 | * Default response status code |
||
27 | * @var integer |
||
28 | */ |
||
29 | public $response_status_code = 200; |
||
30 | |||
31 | |||
32 | /** |
||
33 | * Default response content type |
||
34 | * @var integer |
||
35 | */ |
||
36 | public $response_content_type = "text/html"; |
||
37 | |||
38 | |||
39 | /** |
||
40 | * Request attribute name for the Twig template |
||
41 | * @var string |
||
42 | */ |
||
43 | public $template_attribute_name = 'template'; |
||
44 | |||
45 | |||
46 | /** |
||
47 | * Request attribute name for the Twig template context variables |
||
48 | * @var string |
||
49 | */ |
||
50 | public $context_attribute_name = 'context'; |
||
51 | |||
52 | |||
53 | /** |
||
54 | * @param TwigEnvironment $twig Twig Environment |
||
55 | * @param ResponseFactoryInterface $response_factory PSR-17 Response Factory |
||
56 | */ |
||
57 | 2 | public function __construct(TwigEnvironment $twig, ResponseFactoryInterface $response_factory) |
|
62 | |||
63 | |||
64 | |||
65 | /** |
||
66 | * @inheritDoc |
||
67 | */ |
||
68 | 14 | public function handle(ServerRequestInterface $request) : ResponseInterface |
|
107 | |||
108 | |||
109 | |||
110 | /** |
||
111 | * Sets the Twig Environment. |
||
112 | * |
||
113 | * @param TwigEnvironment $twig |
||
114 | */ |
||
115 | 18 | public function setTwig(TwigEnvironment $twig) : self |
|
120 | |||
121 | |||
122 | /** |
||
123 | * Sets the Response Factory. |
||
124 | * |
||
125 | * @param ResponseFactoryInterface $response_factory PSR-17 ResponseFactory |
||
126 | */ |
||
127 | 4 | public function setResponseFactory(ResponseFactoryInterface $response_factory) : self |
|
132 | |||
133 | |||
134 | /** |
||
135 | * Sets the Status code for generated response. |
||
136 | * |
||
137 | * @param int $response_status_code HTTP Status Code |
||
138 | */ |
||
139 | 4 | public function setResponseStatusCode(int $response_status_code) : self |
|
144 | |||
145 | |||
146 | /** |
||
147 | * Sets the content-type for generated response. |
||
148 | * |
||
149 | * @param string $response_content_type Response Content-type |
||
150 | */ |
||
151 | 4 | public function setResponseContentType(string $response_content_type) : self |
|
156 | |||
157 | |||
158 | /** |
||
159 | * Sets the request attribute that carries the template. |
||
160 | * |
||
161 | * @param string $attr Request attribute name |
||
162 | */ |
||
163 | 16 | public function setTemplateAttributeName(string $attr) : self |
|
168 | |||
169 | |||
170 | /** |
||
171 | * Sets the request attribute that carries the context array. |
||
172 | * |
||
173 | * @param string $attr Request attribute name |
||
174 | */ |
||
175 | 16 | public function setContextAttributeName(string $attr) : self |
|
180 | } |
||
181 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.