-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
In our usage we need to extend the ControllerInvoker to have responses normalised from a generic Payload into a standard Response. To make this easier it would be helpful if some private methods were instead protected and the Invoker fetching the default resolver chain were separated out from the creation of the ControllerInvoker. Fixes #105
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,13 @@ public static function create(?ContainerInterface $container = null): App | |
return $app; | ||
} | ||
|
||
private static function createControllerInvoker(ContainerInterface $container): ControllerInvoker | ||
/** | ||
* Create an invoker with the default resolvers. | ||
* | ||
* @param ContainerInterface $container | ||
Check failure on line 45 in src/Bridge.php GitHub Actions / Coding standards
|
||
* @return Invoker | ||
Check failure on line 46 in src/Bridge.php GitHub Actions / Coding standards
|
||
*/ | ||
protected static function createInvoker(ContainerInterface $container): Invoker | ||
{ | ||
$resolvers = [ | ||
// Inject parameters by name first | ||
|
@@ -50,8 +56,17 @@ private static function createControllerInvoker(ContainerInterface $container): | |
new DefaultValueResolver, | ||
]; | ||
|
||
$invoker = new Invoker(new ResolverChain($resolvers), $container); | ||
return new Invoker(new ResolverChain($resolvers), $container); | ||
} | ||
|
||
return new ControllerInvoker($invoker); | ||
/** | ||
* Create a controller invoker with the default resolvers. | ||
* | ||
* @param ContainerInterface $container | ||
Check failure on line 65 in src/Bridge.php GitHub Actions / Coding standards
|
||
* @return ControllerInvoker | ||
Check failure on line 66 in src/Bridge.php GitHub Actions / Coding standards
|
||
*/ | ||
protected static function createControllerInvoker(ContainerInterface $container): ControllerInvoker | ||
{ | ||
return new ControllerInvoker(self::createInvoker($container)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,10 +42,28 @@ public function __invoke( | |
// Inject the attributes defined on the request | ||
$parameters += $request->getAttributes(); | ||
|
||
return $this->invoker->call($callable, $parameters); | ||
return $this->processResponse($this->invoker->call($callable, $parameters)); | ||
} | ||
|
||
private static function injectRouteArguments(ServerRequestInterface $request, array $routeArguments): ServerRequestInterface | ||
/** | ||
* Allow for child classes to process the response. | ||
* | ||
* @param ResponseInterface|string The response from the callable. | ||
* @return ResponseInterface|string The processed response | ||
*/ | ||
protected function processResponse($response) | ||
Check failure on line 54 in src/ControllerInvoker.php GitHub Actions / Coding standards
|
||
{ | ||
return $response; | ||
} | ||
|
||
/** | ||
* Inject route arguments into the request. | ||
* | ||
* @param ServerRequestInterface $request | ||
Check failure on line 62 in src/ControllerInvoker.php GitHub Actions / Coding standards
|
||
* @param array $routeArguments | ||
* @return ServerRequestInterface | ||
Check failure on line 64 in src/ControllerInvoker.php GitHub Actions / Coding standards
|
||
*/ | ||
protected static function injectRouteArguments(ServerRequestInterface $request, array $routeArguments): ServerRequestInterface | ||
{ | ||
$requestWithArgs = $request; | ||
foreach ($routeArguments as $key => $value) { | ||
|