aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front/controller/visitor/ErrorNotFoundController.php
blob: 758dd83ba3d55bd9b06cb7222ea18a6f9486d2e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php

declare(strict_types=1);

namespace Shaarli\Front\Controller\Visitor;

use Slim\Http\Request;
use Slim\Http\Response;

/**
 * Controller used to render the 404 error page.
 */
class ErrorNotFoundController extends ShaarliVisitorController
{
    public function __invoke(Request $request, Response $response): Response
    {
        // Request from the API
        if (false !== strpos($request->getRequestTarget(), '/api/v1')) {
            return $response->withStatus(404);
        }

        // This is required because the middleware is ignored if the route is not found.
        $this->container->basePath = rtrim($request->getUri()->getBasePath(), '/');

        $this->assignView('error_message', t('Requested page could not be found.'));

        return $response->withStatus(404)->write($this->render('404'));
    }
}