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

Commit

Permalink
ServerRequest object injected by ApplicationServer into View globals
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed Feb 26, 2019
1 parent 724b7fb commit 941559a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/ApplicationResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,7 @@ class ApplicationResponse
private $headers;

public function __construct(
ServerRequestInterface $request,
string $controllerClass,
ControllerResponse $controllerResponse,
Config $config,
Expand All @@ -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
Expand Down

0 comments on commit 941559a

Please sign in to comment.