summaryrefslogtreecommitdiff
path: root/src/Middleware/NotFoundResponse.php
blob: c5d51d2d09b22d7053795140e4b838133baf07b7 (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

namespace Engelsystem\Middleware;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class NotFoundResponse implements MiddlewareInterface
{
    /**
     * Returns a 404: Page not found response
     *
     * Should be the last middleware
     *
     * @param ServerRequestInterface  $request
     * @param RequestHandlerInterface $handler
     * @return ResponseInterface
     */
    public function process(
        ServerRequestInterface $request,
        RequestHandlerInterface $handler
    ): ResponseInterface {
        global $user;
        $event_config = EventConfig();
        $content = info(
            _('This page could not be found or you don\'t have permission to view it. You probably have to sign in or register in order to gain access!'),
            true
        );

        return response(view(__DIR__ . '/../../templates/layout.html', [
            'theme'          => isset($user) ? $user['color'] : config('theme'),
            'title'          => _('Page not found'),
            'atom_link'      => '',
            'start_page_url' => page_link_to('/'),
            'credits_url'    => page_link_to('credits'),
            'menu'           => make_menu(),
            'content'        => msg() . $content,
            'header_toolbar' => header_toolbar(),
            'faq_url'        => config('faq_url'),
            'contact_email'  => config('contact_email'),
            'locale'         => locale(),
            'event_info'     => EventConfig_info($event_config) . ' <br />'
        ]), 404);
    }
}