Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Middlewares must not pass their params by reference, to preserver Res…
Browse files Browse the repository at this point in the history
…ponse / Request immutability
  • Loading branch information
cdujeu committed May 12, 2016
1 parent 1ec0ad7 commit 44620ba
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/src/core/src/pydio/Core/Controller/Controller.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static function parseRestParameters(ServerRequestInterface &$request){
* @return ResponseInterface * @return ResponseInterface
* @throws AuthRequiredException * @throws AuthRequiredException
*/ */
public static function registryActionMiddleware(ServerRequestInterface &$request, ResponseInterface &$response, callable $nextCallable = null){ public static function registryActionMiddleware(ServerRequestInterface $request, ResponseInterface $response, callable $nextCallable = null){
$action = null; $action = null;
if(ConfService::currentContextIsRestAPI()){ if(ConfService::currentContextIsRestAPI()){
$action = Controller::parseRestParameters($request); $action = Controller::parseRestParameters($request);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AuthCliMiddleware
* @return ResponseInterface * @return ResponseInterface
* @throws AuthRequiredException * @throws AuthRequiredException
*/ */
public static function handleRequest(ServerRequestInterface &$requestInterface, ResponseInterface &$responseInterface, callable $next = null){ public static function handleRequest(ServerRequestInterface $requestInterface, ResponseInterface $responseInterface, callable $next = null){




$options = $requestInterface->getAttribute("cli-options"); $options = $requestInterface->getAttribute("cli-options");
Expand Down
2 changes: 1 addition & 1 deletion core/src/core/src/pydio/Core/Http/Cli/CliMiddleware.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CliMiddleware
* @param callable|null $next * @param callable|null $next
* @throws WorkspaceNotFoundException * @throws WorkspaceNotFoundException
*/ */
public static function handleRequest(ServerRequestInterface &$requestInterface, ResponseInterface &$responseInterface, callable $next = null){ public static function handleRequest(ServerRequestInterface $requestInterface, ResponseInterface $responseInterface, callable $next = null){


/** /**
* @var OutputInterface * @var OutputInterface
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class SapiMiddleware class SapiMiddleware
{ {


public static function handleRequest(ServerRequestInterface &$request, ResponseInterface &$response, callable $next = null){ public static function handleRequest(ServerRequestInterface $request, ResponseInterface $response, callable $next = null){


$params = $request->getQueryParams(); $params = $request->getQueryParams();
$postParams = $request->getParsedBody(); $postParams = $request->getParsedBody();
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SecureTokenMiddleware
* @param callable|null $next * @param callable|null $next
* @throws PydioException * @throws PydioException
*/ */
public static function handleRequest(\Psr\Http\Message\ServerRequestInterface &$requestInterface, \Psr\Http\Message\ResponseInterface &$responseInterface, callable $next = null){ public static function handleRequest(\Psr\Http\Message\ServerRequestInterface $requestInterface, \Psr\Http\Message\ResponseInterface $responseInterface, callable $next = null){


$pluginsUnSecureActions = ConfService::getDeclaredUnsecureActions(); $pluginsUnSecureActions = ConfService::getDeclaredUnsecureActions();
$pluginsUnSecureActions[] = "get_secure_token"; $pluginsUnSecureActions[] = "get_secure_token";
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class SessionMiddleware class SessionMiddleware
{ {


public static function handleRequest(\Psr\Http\Message\ServerRequestInterface &$requestInterface, \Psr\Http\Message\ResponseInterface &$responseInterface, callable $next = null){ public static function handleRequest(\Psr\Http\Message\ServerRequestInterface $requestInterface, \Psr\Http\Message\ResponseInterface $responseInterface, callable $next = null){


$getParams = $requestInterface->getQueryParams(); $getParams = $requestInterface->getQueryParams();
$sessionName = SessionService::getSessionName(); $sessionName = SessionService::getSessionName();
Expand Down
10 changes: 5 additions & 5 deletions core/src/core/src/pydio/Core/Http/Server.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function nextCallable(&$request, &$response){
if($this->middleWares->valid()){ if($this->middleWares->valid()){
$callable = $this->middleWares->current(); $callable = $this->middleWares->current();
$this->middleWares->next(); $this->middleWares->next();
$response = call_user_func_array($callable, array(&$request, &$response, function($req, $res){ $response = call_user_func_array($callable, array($request, $response, function($req, $res){
return $this->nextCallable($req, $res); return $this->nextCallable($req, $res);
})); }));
} }
Expand All @@ -111,9 +111,9 @@ protected function nextCallable(&$request, &$response){
* @param callable|null $next * @param callable|null $next
* @return ResponseInterface * @return ResponseInterface
*/ */
public static function callNextMiddleWare(ServerRequestInterface &$requestInterface, ResponseInterface &$responseInterface, callable $next = null){ public static function callNextMiddleWare(ServerRequestInterface $requestInterface, ResponseInterface $responseInterface, callable $next = null){
if($next !== null){ if($next !== null){
$responseInterface = call_user_func_array($next, array(&$requestInterface, &$responseInterface)); $responseInterface = call_user_func_array($next, array($requestInterface, $responseInterface));
} }
return $responseInterface; return $responseInterface;
} }
Expand All @@ -125,9 +125,9 @@ public static function callNextMiddleWare(ServerRequestInterface &$requestInterf
* @param callable|null $next * @param callable|null $next
* @return ResponseInterface * @return ResponseInterface
*/ */
public static function callNextMiddleWareAndRewind(callable $comparisonFunction, ServerRequestInterface &$requestInterface, ResponseInterface &$responseInterface, callable $next = null){ public static function callNextMiddleWareAndRewind(callable $comparisonFunction, ServerRequestInterface $requestInterface, ResponseInterface $responseInterface, callable $next = null){
if($next !== null){ if($next !== null){
$responseInterface = call_user_func_array($next, array(&$requestInterface, &$responseInterface)); $responseInterface = call_user_func_array($next, array($requestInterface, $responseInterface));
} }
self::$middleWareInstance->rewind(); self::$middleWareInstance->rewind();
while(!$comparisonFunction(self::$middleWareInstance->current())){ while(!$comparisonFunction(self::$middleWareInstance->current())){
Expand Down

0 comments on commit 44620ba

Please sign in to comment.