Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Commit 941559a

Browse files
committed
ServerRequest object injected by ApplicationServer into View globals
1 parent 724b7fb commit 941559a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ private function notFound($status, $message) : void
108108
$errorHandlerClass = $this->config->get('app')->get('http-error-handler');
109109
$errorHandler = new $errorHandlerClass($status, $message);
110110
$this->response = new ApplicationResponse(
111+
$this->request,
111112
$errorHandlerClass,
112113
$errorHandler(),
113114
$this->config,
@@ -144,6 +145,7 @@ private function runController($controllerClass, array $args) : void
144145
{
145146
$controller = new FrontController($this->container, $this->request, $controllerClass, $args);
146147
$this->response = new ApplicationResponse(
148+
$this->request,
147149
$controllerClass,
148150
$controller->getControllerResponse(),
149151
$this->config,

src/ApplicationResponse.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Selami;
55

66
use Psr\Http\Message\ResponseInterface;
7+
use Psr\Http\Message\ServerRequestInterface;
78
use Zend\Config\Config;
89
use Selami\View\ViewInterface;
910
use Selami\Router\Router;
@@ -26,6 +27,7 @@ class ApplicationResponse
2627
private $headers;
2728

2829
public function __construct(
30+
ServerRequestInterface $request,
2931
string $controllerClass,
3032
ControllerResponse $controllerResponse,
3133
Config $config,
@@ -37,6 +39,11 @@ public function __construct(
3739
$this->headers = isset( $config->get('app')['default_headers']) ?
3840
$config->get('app')->get('default_headers')->toArray() : [];
3941
$this->view = $view;
42+
$this->view->addGlobal('Request', $request);
43+
$this->view->addGlobal(
44+
'QueryParameters',
45+
array_merge($request->getQueryParams(), $request->getParsedBody())
46+
);
4047
}
4148

4249
public function getResponseHeaders() : array

0 commit comments

Comments
 (0)