From 941559af790a52d4ae0aa79e339ede9b48332fbd Mon Sep 17 00:00:00 2001 From: Mehmet Korkmaz Date: Tue, 26 Feb 2019 03:35:38 +0300 Subject: [PATCH] ServerRequest object injected by ApplicationServer into View globals --- src/Application.php | 2 ++ src/ApplicationResponse.php | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/Application.php b/src/Application.php index eb7f104..ff47962 100644 --- a/src/Application.php +++ b/src/Application.php @@ -108,6 +108,7 @@ private function notFound($status, $message) : void $errorHandlerClass = $this->config->get('app')->get('http-error-handler'); $errorHandler = new $errorHandlerClass($status, $message); $this->response = new ApplicationResponse( + $this->request, $errorHandlerClass, $errorHandler(), $this->config, @@ -144,6 +145,7 @@ private function runController($controllerClass, array $args) : void { $controller = new FrontController($this->container, $this->request, $controllerClass, $args); $this->response = new ApplicationResponse( + $this->request, $controllerClass, $controller->getControllerResponse(), $this->config, diff --git a/src/ApplicationResponse.php b/src/ApplicationResponse.php index 0d05fd6..e66e021 100644 --- a/src/ApplicationResponse.php +++ b/src/ApplicationResponse.php @@ -4,6 +4,7 @@ namespace Selami; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; use Zend\Config\Config; use Selami\View\ViewInterface; use Selami\Router\Router; @@ -26,6 +27,7 @@ class ApplicationResponse private $headers; public function __construct( + ServerRequestInterface $request, string $controllerClass, ControllerResponse $controllerResponse, Config $config, @@ -37,6 +39,11 @@ public function __construct( $this->headers = isset( $config->get('app')['default_headers']) ? $config->get('app')->get('default_headers')->toArray() : []; $this->view = $view; + $this->view->addGlobal('Request', $request); + $this->view->addGlobal( + 'QueryParameters', + array_merge($request->getQueryParams(), $request->getParsedBody()) + ); } public function getResponseHeaders() : array