Http\AbstractServer: Allow usage as PSR-7 middleware

This commit is contained in:
Franz Liedke 2016-04-16 13:10:11 +09:00
parent f403feb3b1
commit 181c19eac7
No known key found for this signature in database
GPG Key ID: 9A0231A879B055F4

View File

@ -15,6 +15,8 @@ use Flarum\Core\EmailToken;
use Flarum\Core\PasswordToken;
use Flarum\Foundation\AbstractServer as BaseAbstractServer;
use Flarum\Foundation\Application;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Server;
use Zend\Stratigility\MiddlewareInterface;
@ -36,6 +38,23 @@ abstract class AbstractServer extends BaseAbstractServer
$server->listen();
}
/**
* Use as PSR-7 middleware
*
* @param $request
* @param $response
* @param null $out
* @return mixed
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out = null)
{
$this->collectGarbage($this->app);
$middleware = $this->getMiddleware($this->app);
return $middleware($request, $response, $out);
}
/**
* @param Application $app
* @return MiddlewareInterface