Skip to content

[BC-Break] Add request and response object to the preHandle and postHandle hooks #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Bootstraps/HooksInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace PHPPM\Bootstraps;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

interface HooksInterface
{
public function preHandle($app);
public function postHandle($app);
public function preHandle($app, ServerRequestInterface $request);
public function postHandle($app, ServerRequestInterface $request, ResponseInterface $response);
}
9 changes: 7 additions & 2 deletions Bootstraps/Laravel.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace PHPPM\Bootstraps;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
* A default bootstrap for the Laravel framework
Expand Down Expand Up @@ -120,16 +122,19 @@ public function getApplication()

/**
* @param \Illuminate\Contracts\Foundation\Application $app
* @param ServerRequestInterface $request
*/
public function preHandle($app)
public function preHandle($app, ServerRequestInterface $request)
{
//reset const LARAVEL_START, to get the correct timing
}

/**
* @param \Illuminate\Contracts\Foundation\Application $app
* @param ServerRequestInterface $request
* @param ResponseInterface $response
*/
public function postHandle($app)
public function postHandle($app, ServerRequestInterface $request, ResponseInterface $response)
{
//check if this is a lumen framework, if so, do not reset
//note that lumen does not have the getProvider method
Expand Down
9 changes: 7 additions & 2 deletions Bootstraps/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use PHPPM\Symfony\StrongerNativeSessionStorage;
use PHPPM\Utils;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\HttpFoundation\Request;
use function PHPPM\register_file;

Expand Down Expand Up @@ -116,8 +118,9 @@ protected function getVendorDir()
* Does some necessary preparation before each request.
*
* @param \AppKernel $app
* @param ServerRequestInterface $request
*/
public function preHandle($app)
public function preHandle($app, ServerRequestInterface $request)
{
//resets Kernels startTime, so Symfony can correctly calculate the execution time
Utils::hijackProperty($app, 'startTime', microtime(true));
Expand All @@ -127,8 +130,10 @@ public function preHandle($app)
* Does some necessary clean up after each request.
*
* @param \AppKernel $app
* @param ServerRequestInterface $request
* @param ResponseInterface $response
*/
public function postHandle($app)
public function postHandle($app, ServerRequestInterface $request, ResponseInterface $response)
{
$container = $app->getContainer();

Expand Down
4 changes: 2 additions & 2 deletions Bridges/HttpKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function handle(ServerRequestInterface $request)
ob_start();

if ($this->bootstrap instanceof HooksInterface) {
$this->bootstrap->preHandle($this->application);
$this->bootstrap->preHandle($this->application, $request);
}

$syResponse = $this->application->handle($syRequest);
Expand All @@ -98,7 +98,7 @@ public function handle(ServerRequestInterface $request)
}

if ($this->bootstrap instanceof HooksInterface) {
$this->bootstrap->postHandle($this->application);
$this->bootstrap->postHandle($this->application, $request, $response);
}

return $response;
Expand Down