1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* webtrees: online genealogy |
4
|
|
|
* Copyright (C) 2019 webtrees development team |
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU General Public License as published by |
7
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* This program is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU General Public License for more details. |
13
|
|
|
* You should have received a copy of the GNU General Public License |
14
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
15
|
|
|
*/ |
16
|
|
|
declare(strict_types=1); |
17
|
|
|
|
18
|
|
|
namespace Fisharebest\Webtrees\Http\Middleware; |
19
|
|
|
|
20
|
|
|
use Illuminate\Support\Str; |
21
|
|
|
use Psr\Http\Message\ResponseInterface; |
22
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
23
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
24
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
25
|
|
|
use function app; |
26
|
|
|
use function explode; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Take an HTTP request, and forward it to a webtrees RequestHandler. |
30
|
|
|
*/ |
31
|
|
|
class RequestRouter implements MiddlewareInterface |
32
|
|
|
{ |
33
|
|
|
private const CONTROLLER_NAMESPACE = '\\Fisharebest\\Webtrees\\Http\\Controllers\\'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param ServerRequestInterface $request |
37
|
|
|
* @param RequestHandlerInterface $handler |
38
|
|
|
* |
39
|
|
|
* @return ResponseInterface |
40
|
|
|
*/ |
41
|
|
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
42
|
|
|
{ |
43
|
|
|
// Load the route and routing table. |
44
|
|
|
$route = $request->getQueryParams()['route']; |
45
|
|
|
$routes = require 'routes/web.php'; |
46
|
|
|
|
47
|
|
|
// Find the routing for the selected route. |
48
|
|
|
$routing = $routes[$request->getMethod() . ':' . $route] ?? 'ErrorController@noRouteFound'; |
49
|
|
|
|
50
|
|
|
// Routes defined using controller@action |
51
|
|
|
if (Str::contains($routing, '@')) { |
52
|
|
|
[$class, $method] = explode('@', $routing); |
53
|
|
|
|
54
|
|
|
app()->instance(ServerRequestInterface::class, $request); |
55
|
|
|
|
56
|
|
|
$controller = app(self::CONTROLLER_NAMESPACE . $class); |
57
|
|
|
|
58
|
|
|
return app()->dispatch($controller, $method); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// Routes defined using a request handler |
62
|
|
|
return app($routing)->handle($request); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.