Extract destroy action from Setup\ServersController
Extracts it into a new controller called Setup\ServerDestroyController. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
9cac3a9bcc
commit
2fe67cc85b
@ -3780,6 +3780,11 @@ parameters:
|
||||
count: 1
|
||||
path: src/Controllers/Setup/MainController.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$config of class PhpMyAdmin\\\\Controllers\\\\Setup\\\\ServerDestroyController constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
|
||||
count: 1
|
||||
path: src/Controllers/Setup/MainController.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$config of class PhpMyAdmin\\\\Controllers\\\\Setup\\\\ServersController constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
|
||||
count: 1
|
||||
|
||||
@ -64,9 +64,8 @@ final class MainController implements InvocableController
|
||||
}
|
||||
|
||||
if ($page === 'servers') {
|
||||
$controller = new ServersController($GLOBALS['ConfigFile'], $this->template);
|
||||
if ($request->getQueryParam('mode') === 'remove' && $request->isPost()) {
|
||||
$controller->destroy($request);
|
||||
(new ServerDestroyController($GLOBALS['ConfigFile'], $this->template))($request);
|
||||
$response = $response->withStatus(StatusCodeInterface::STATUS_FOUND);
|
||||
|
||||
return $response->withHeader(
|
||||
@ -75,7 +74,7 @@ final class MainController implements InvocableController
|
||||
);
|
||||
}
|
||||
|
||||
return $response->write($controller->index($request));
|
||||
return $response->write((new ServersController($GLOBALS['ConfigFile'], $this->template))($request));
|
||||
}
|
||||
|
||||
return $response->write((new HomeController($GLOBALS['ConfigFile'], $this->template))($request));
|
||||
|
||||
35
src/Controllers/Setup/ServerDestroyController.php
Normal file
35
src/Controllers/Setup/ServerDestroyController.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Setup;
|
||||
|
||||
use PhpMyAdmin\Http\ServerRequest;
|
||||
|
||||
use function is_numeric;
|
||||
|
||||
class ServerDestroyController extends AbstractController
|
||||
{
|
||||
public function __invoke(ServerRequest $request): void
|
||||
{
|
||||
$id = $this->getIdParam($request->getQueryParam('id'));
|
||||
$hasServer = $id >= 1 && $this->config->get('Servers/' . $id) !== null;
|
||||
if (! $hasServer) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->config->removeServer($id);
|
||||
}
|
||||
|
||||
/** @psalm-return int<0, max> */
|
||||
private function getIdParam(mixed $idParam): int
|
||||
{
|
||||
if (! is_numeric($idParam)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$id = (int) $idParam;
|
||||
|
||||
return $id >= 1 ? $id : 0;
|
||||
}
|
||||
}
|
||||
@ -16,7 +16,7 @@ use function ob_start;
|
||||
|
||||
class ServersController extends AbstractController
|
||||
{
|
||||
public function index(ServerRequest $request): string
|
||||
public function __invoke(ServerRequest $request): string
|
||||
{
|
||||
$id = $this->getIdParam($request->getQueryParam('id'));
|
||||
$mode = $this->getModeParam($request->getQueryParam('mode'));
|
||||
@ -44,17 +44,6 @@ class ServersController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy(ServerRequest $request): void
|
||||
{
|
||||
$id = $this->getIdParam($request->getQueryParam('id'));
|
||||
$hasServer = $id >= 1 && $this->config->get('Servers/' . $id) !== null;
|
||||
if (! $hasServer) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->config->removeServer($id);
|
||||
}
|
||||
|
||||
private function getFormSetParam(mixed $formSetParam): string
|
||||
{
|
||||
return is_string($formSetParam) ? $formSetParam : '';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user