3 namespace Shaarli\Front
;
5 use Shaarli\Container\ShaarliContainer
;
6 use Shaarli\Front\Exception\ShaarliException
;
8 use Slim\Http\Response
;
11 * Class ShaarliMiddleware
13 * This will be called before accessing any Shaarli controller.
15 class ShaarliMiddleware
17 /** @var ShaarliContainer contains all Shaarli DI */
20 public function __construct(ShaarliContainer
$container)
22 $this->container
= $container;
26 * Middleware execution:
27 * - execute the controller
28 * - return the response
30 * In case of error, the error template will be displayed with the exception message.
32 * @param Request $request Slim request
33 * @param Response $response Slim response
34 * @param callable $next Next action
36 * @return Response response.
38 public function __invoke(Request
$request, Response
$response, callable
$next)
41 $response = $next($request, $response);
42 } catch (ShaarliException
$e) {
43 $this->container
->pageBuilder
->assign('message', $e->getMessage());
44 if ($this->container
->conf
->get('dev.debug', false)) {
45 $this->container
->pageBuilder
->assign(
47 nl2br(get_class($this) .': '. $e->getTraceAsString())
51 $response = $response->withStatus($e->getCode());
52 $response = $response->write($this->container
->pageBuilder
->render('error'));