Add type hints to Dispatch classes
This commit is contained in:
parent
e9fb474eb7
commit
ecc077a1be
|
|
@ -1,7 +1,8 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<psalm
|
<psalm
|
||||||
errorLevel="3"
|
errorLevel="2"
|
||||||
resolveFromConfigFile="true"
|
resolveFromConfigFile="true"
|
||||||
|
allowStringToStandInForClass="true"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns="https://getpsalm.org/schema/config"
|
xmlns="https://getpsalm.org/schema/config"
|
||||||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
|
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,9 @@ use Psr\Http\Message\ServerRequestInterface;
|
||||||
*/
|
*/
|
||||||
class DispatchStack implements DispatchStackInterface
|
class DispatchStack implements DispatchStackInterface
|
||||||
{
|
{
|
||||||
|
/** @var mixed[] */
|
||||||
private $stack;
|
private $stack;
|
||||||
|
/** @var DispatcherInterface */
|
||||||
private $dispatcher;
|
private $dispatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -66,7 +68,10 @@ class DispatchStack implements DispatchStackInterface
|
||||||
|
|
||||||
// The final middleware's $next returns $response unchanged and sets
|
// The final middleware's $next returns $response unchanged and sets
|
||||||
// the $stackCompleted flag to indicate the stack has completed.
|
// the $stackCompleted flag to indicate the stack has completed.
|
||||||
$chain = function ($request, $response) use (&$stackCompleted) {
|
$chain = function (
|
||||||
|
ServerRequestInterface $request,
|
||||||
|
ResponseInterface $response
|
||||||
|
) use (&$stackCompleted): ResponseInterface {
|
||||||
$stackCompleted = true;
|
$stackCompleted = true;
|
||||||
return $response;
|
return $response;
|
||||||
};
|
};
|
||||||
|
|
@ -77,8 +82,16 @@ class DispatchStack implements DispatchStackInterface
|
||||||
// contain a dispatcher, the associated middleware, and a $next function
|
// contain a dispatcher, the associated middleware, and a $next function
|
||||||
// that serves as the link to the next middleware in the chain.
|
// that serves as the link to the next middleware in the chain.
|
||||||
foreach (array_reverse($this->stack) as $middleware) {
|
foreach (array_reverse($this->stack) as $middleware) {
|
||||||
$chain = function ($request, $response) use ($dispatcher, $middleware, $chain) {
|
$chain = function (
|
||||||
return $dispatcher->dispatch($middleware, $request, $response, $chain);
|
ServerRequestInterface $request,
|
||||||
|
ResponseInterface $response
|
||||||
|
) use ($dispatcher, $middleware, $chain): ResponseInterface {
|
||||||
|
return $dispatcher->dispatch(
|
||||||
|
$middleware,
|
||||||
|
$request,
|
||||||
|
$response,
|
||||||
|
$chain
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,10 @@ class Dispatcher implements DispatcherInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed[] $dispatchables
|
||||||
|
* @return DispatchStack
|
||||||
|
*/
|
||||||
protected function getDispatchStack($dispatchables)
|
protected function getDispatchStack($dispatchables)
|
||||||
{
|
{
|
||||||
$stack = new DispatchStack($this);
|
$stack = new DispatchStack($this);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue