Skip to content

Commit

Permalink
Refactor server engines entry point
Browse files Browse the repository at this point in the history
Moves server engines entry point logic to the routes files and moves the
request parameters to the route parameter.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Oct 26, 2019
1 parent 9372bae commit 6dd961c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 48 deletions.
5 changes: 1 addition & 4 deletions libraries/classes/DatabaseInterface.php
Expand Up @@ -2267,10 +2267,7 @@ public static function formatError(int $error_number, string $error_message): st
*/
$error .= ' - ' . $error_message .
' (<a href="' .
Url::getFromRoute('/server/engines', [
'engine' => 'InnoDB',
'page' => 'Status',
]) .
Url::getFromRoute('/server/engines/InnoDB/Status') .
'">' . __('Details…') . '</a>)';
}
} else {
Expand Down
7 changes: 2 additions & 5 deletions libraries/classes/Server/Status/Data.php
Expand Up @@ -193,14 +193,11 @@ private function _getLinks()
$links['Slow_queries']['doc'] = 'slow_query_log';

$links['innodb'][__('Variables')] = [
'url' => Url::getFromRoute('/server/engines', ['engine' => 'InnoDB']),
'url' => Url::getFromRoute('/server/engines/InnoDB'),
'params' => '',
];
$links['innodb'][__('InnoDB Status')] = [
'url' => Url::getFromRoute('/server/engines', [
'engine' => 'InnoDB',
'page' => 'Status',
]),
'url' => Url::getFromRoute('/server/engines/InnoDB/Status'),
'params' => '',
];
$links['innodb']['doc'] = 'innodb';
Expand Down
31 changes: 0 additions & 31 deletions libraries/entry_points/server/engines.php

This file was deleted.

12 changes: 10 additions & 2 deletions libraries/routes.php
Expand Up @@ -9,6 +9,7 @@
use PhpMyAdmin\Controllers\Server\BinlogController;
use PhpMyAdmin\Controllers\Server\CollationsController;
use PhpMyAdmin\Controllers\Server\DatabasesController;
use PhpMyAdmin\Controllers\Server\EnginesController;
use PhpMyAdmin\Response;

global $containerBuilder;
Expand Down Expand Up @@ -174,8 +175,15 @@
]));
});
});
$routes->addRoute('GET', '/engines', function () {
require_once ROOT_PATH . 'libraries/entry_points/server/engines.php';
$routes->addGroup('/engines', function (RouteCollector $routes) use ($containerBuilder, $response) {
/** @var EnginesController $controller */
$controller = $containerBuilder->get(EnginesController::class);
$routes->addRoute('GET', '', function () use ($response, $controller) {
$response->addHTML($controller->index());
});
$routes->addRoute('GET', '/{engine}[/{page}]', function (array $vars) use ($response, $controller) {
$response->addHTML($controller->show($vars));
});
});
$routes->addRoute(['GET', 'POST'], '/export', function () {
require_once ROOT_PATH . 'libraries/entry_points/server/export.php';
Expand Down
2 changes: 1 addition & 1 deletion templates/server/engines/index.twig
Expand Up @@ -20,7 +20,7 @@
{{- details['Support'] == 'NO' or details['Support'] == 'DISABLED' ? ' disabled' }}
{{ details['Support'] == 'DEFAULT' ? ' marked' }}">
<td>
<a rel="newpage" href="{{ url('/server/engines', {'engine': engine}) }}">
<a rel="newpage" href="{{ url('/server/engines/' ~ engine) }}">
{{ details['Engine'] }}
</a>
</td>
Expand Down
4 changes: 2 additions & 2 deletions templates/server/engines/show.twig
Expand Up @@ -17,7 +17,7 @@
{% if page is empty %}
<strong>{% trans 'Variables' %}</strong>
{% else %}
<a href="{{ url('/server/engines', {'engine': engine.engine}) }}">
<a href="{{ url('/server/engines/' ~ engine.engine) }}">
{% trans 'Variables' %}
</a>
{% endif %}
Expand All @@ -26,7 +26,7 @@
{% if page is defined and page == current %}
<strong>{{ label }}</strong>
{% else %}
<a href="{{ url('/server/engines', {'engine': engine.engine, 'page': current}) }}">
<a href="{{ url('/server/engines/' ~ engine.engine ~ '/' ~ current) }}">
{{ label }}
</a>
{% endif %}
Expand Down
6 changes: 3 additions & 3 deletions test/classes/Controllers/Server/EnginesControllerTest.php
Expand Up @@ -73,7 +73,7 @@ public function testIndex(): void
$actual
);
$this->assertStringContainsString(
'index.php?route=/server/engines&amp;engine=FEDERATED',
'index.php?route=/server/engines/FEDERATED',
$actual
);

Expand All @@ -86,7 +86,7 @@ public function testIndex(): void
$actual
);
$this->assertStringContainsString(
'index.php?route=/server/engines&amp;engine=dummy',
'index.php?route=/server/engines/dummy',
$actual
);
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public function testShow(): void
$actual
);
$this->assertStringContainsString(
'index.php?route=/server/engines&amp;engine=Pbxt&amp;page=Documentation',
'index.php?route=/server/engines/Pbxt/Documentation',
$actual
);
$this->assertStringContainsString(
Expand Down

0 comments on commit 6dd961c

Please sign in to comment.