-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathMainController.php
More file actions
79 lines (68 loc) · 2.24 KB
/
MainController.php
File metadata and controls
79 lines (68 loc) · 2.24 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Setup;
use PhpMyAdmin\Config;
use PhpMyAdmin\Controllers\InvocableController;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
use function in_array;
final readonly class MainController implements InvocableController
{
public function __construct(
private ResponseFactory $responseFactory,
private ResponseRenderer $responseRenderer,
private Template $template,
private Config $config,
) {
}
public function __invoke(ServerRequest $request): Response
{
$page = $this->getPageParam($request->getQueryParam('page'));
if ($page === 'form') {
return (new FormController(
$this->responseFactory,
$this->responseRenderer,
$this->template,
$this->config,
))($request);
}
if ($page === 'config') {
return (new ConfigController(
$this->responseFactory,
$this->responseRenderer,
$this->template,
$this->config,
))($request);
}
if ($page === 'servers' && $request->getQueryParam('mode') === 'remove' && $request->isPost()) {
return (new ServerDestroyController(
$this->responseFactory,
$this->responseRenderer,
$this->template,
$this->config,
))($request);
}
if ($page === 'servers') {
return (new ServersController(
$this->responseFactory,
$this->responseRenderer,
$this->template,
$this->config,
))($request);
}
return (new HomeController(
$this->responseFactory,
$this->responseRenderer,
$this->template,
$this->config,
))($request);
}
/** @psalm-return 'form'|'config'|'servers'|'index' */
private function getPageParam(mixed $pageParam): string
{
return in_array($pageParam, ['form', 'config', 'servers'], true) ? $pageParam : 'index';
}
}