Skip to content

Commit

Permalink
Fix issue with $request->getAttribute('routeInfo')[2] and PHPUnit (cl…
Browse files Browse the repository at this point in the history
…oses #26)
  • Loading branch information
DavidePastore committed Oct 14, 2017
1 parent 7848ccc commit b0dffab
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function __invoke($request, $response, $next)
{
$this->errors = [];
$params = $request->getParams();
$params = array_merge((array) $request->getAttribute('routeInfo')[2], $params);
$params = array_merge((array) $this->retrieveRouteInfo($request), $params);
$this->validate($params, $this->validators);

$request = $request->withAttribute($this->errors_name, $this->getErrors());
Expand Down Expand Up @@ -171,6 +171,21 @@ private function getNestedParam($params = [], $keys = [])
}
}

/**
* Retrieve the route info as an array if any.
*
* @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request
*
* @return array An array with the array info.
*/
private function retrieveRouteInfo($request){
if(isset($request->getAttribute('routeInfo')[2])){
return (array) $request->getAttribute('routeInfo')[2];
} else {
return [];
}
}

/**
* Check if there are any errors.
*
Expand Down

0 comments on commit b0dffab

Please sign in to comment.