diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2021-09-09 23:58:00 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2021-09-09 23:58:00 +0300 |
commit | 94e714a49ba306461d2935906e6fc1a7b8f4addb (patch) | |
tree | 46b8eec7e9fb543a43016829ec5c184089c3d210 /libraries | |
parent | dd0f63f18cd47ea359ad33b426b9d0faf5cbc2ce (diff) |
Extract the `Server\ShowEngineController` class
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/classes/Controllers/Server/EnginesController.php | 41 | ||||
-rw-r--r-- | libraries/classes/Controllers/Server/ShowEngineController.php | 69 | ||||
-rw-r--r-- | libraries/routes.php | 4 | ||||
-rw-r--r-- | libraries/services_controllers.php | 8 |
4 files changed, 80 insertions, 42 deletions
diff --git a/libraries/classes/Controllers/Server/EnginesController.php b/libraries/classes/Controllers/Server/EnginesController.php index e911c722e5..a18998a506 100644 --- a/libraries/classes/Controllers/Server/EnginesController.php +++ b/libraries/classes/Controllers/Server/EnginesController.php @@ -6,7 +6,6 @@ namespace PhpMyAdmin\Controllers\Server; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Http\ServerRequest; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\StorageEngine; use PhpMyAdmin\Template; @@ -30,7 +29,7 @@ class EnginesController extends AbstractController $this->dbi = $dbi; } - public function index(): void + public function __invoke(): void { global $errorUrl; @@ -44,42 +43,4 @@ class EnginesController extends AbstractController 'engines' => StorageEngine::getStorageEngines(), ]); } - - /** - * Displays details about a given Storage Engine - * - * @param array $params Request params - */ - public function show(ServerRequest $request, array $params): void - { - global $errorUrl; - - $errorUrl = Url::getFromRoute('/'); - - if ($this->dbi->isSuperUser()) { - $this->dbi->selectDb('mysql'); - } - - $page = $params['page'] ?? ''; - - $engine = []; - if (StorageEngine::isValid($params['engine'])) { - $storageEngine = StorageEngine::getEngine($params['engine']); - $engine = [ - 'engine' => $params['engine'], - 'title' => $storageEngine->getTitle(), - 'help_page' => $storageEngine->getMysqlHelpPage(), - 'comment' => $storageEngine->getComment(), - 'info_pages' => $storageEngine->getInfoPages(), - 'support' => $storageEngine->getSupportInformationMessage(), - 'variables' => $storageEngine->getHtmlVariables(), - 'page' => ! empty($page) ? $storageEngine->getPage($page) : '', - ]; - } - - $this->render('server/engines/show', [ - 'engine' => $engine, - 'page' => $page, - ]); - } } diff --git a/libraries/classes/Controllers/Server/ShowEngineController.php b/libraries/classes/Controllers/Server/ShowEngineController.php new file mode 100644 index 0000000000..3057f1615d --- /dev/null +++ b/libraries/classes/Controllers/Server/ShowEngineController.php @@ -0,0 +1,69 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Server; + +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\StorageEngine; +use PhpMyAdmin\Template; +use PhpMyAdmin\Url; + +/** + * Displays details about a given Storage Engine. + */ +final class ShowEngineController extends AbstractController +{ + /** @var DatabaseInterface */ + private $dbi; + + /** + * @param ResponseRenderer $response + * @param DatabaseInterface $dbi + */ + public function __construct($response, Template $template, $dbi) + { + parent::__construct($response, $template); + $this->dbi = $dbi; + } + + /** + * @param array $params + * @psalm-param array{engine: string, page?: string} $params + */ + public function __invoke(ServerRequest $request, array $params): void + { + global $errorUrl; + + $errorUrl = Url::getFromRoute('/'); + + if ($this->dbi->isSuperUser()) { + $this->dbi->selectDb('mysql'); + } + + $page = $params['page'] ?? ''; + + $engine = []; + if (StorageEngine::isValid($params['engine'])) { + $storageEngine = StorageEngine::getEngine($params['engine']); + $engine = [ + 'engine' => $params['engine'], + 'title' => $storageEngine->getTitle(), + 'help_page' => $storageEngine->getMysqlHelpPage(), + 'comment' => $storageEngine->getComment(), + 'info_pages' => $storageEngine->getInfoPages(), + 'support' => $storageEngine->getSupportInformationMessage(), + 'variables' => $storageEngine->getHtmlVariables(), + 'page' => ! empty($page) ? $storageEngine->getPage($page) : '', + ]; + } + + $this->render('server/engines/show', [ + 'engine' => $engine, + 'page' => $page, + ]); + } +} diff --git a/libraries/routes.php b/libraries/routes.php index 191d19c7f8..895b3bf86e 100644 --- a/libraries/routes.php +++ b/libraries/routes.php @@ -148,8 +148,8 @@ return static function (RouteCollector $routes): void { $routes->post('/destroy', Server\Databases\DestroyController::class); }); $routes->addGroup('/engines', static function (RouteCollector $routes): void { - $routes->get('', [Server\EnginesController::class, 'index']); - $routes->get('/{engine}[/{page}]', [Server\EnginesController::class, 'show']); + $routes->get('', Server\EnginesController::class); + $routes->get('/{engine}[/{page}]', Server\ShowEngineController::class); }); $routes->addRoute(['GET', 'POST'], '/export', Server\ExportController::class); $routes->addRoute(['GET', 'POST'], '/import', Server\ImportController::class); diff --git a/libraries/services_controllers.php b/libraries/services_controllers.php index f27dbbb705..d58196e5ea 100644 --- a/libraries/services_controllers.php +++ b/libraries/services_controllers.php @@ -833,6 +833,14 @@ return [ '$dbi' => '@dbi', ], ], + Server\ShowEngineController::class => [ + 'class' => Server\ShowEngineController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$dbi' => '@dbi', + ], + ], Server\SqlController::class => [ 'class' => Server\SqlController::class, 'arguments' => [ |