Skip to content

Commit acba6ed

Browse files
committed
Move VersionInformation to constructor in VersionCheckController
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent d4f8ee5 commit acba6ed

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

libraries/classes/Controllers/VersionCheckController.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace PhpMyAdmin\Controllers;
66

77
use PhpMyAdmin\Core;
8+
use PhpMyAdmin\ResponseRenderer;
9+
use PhpMyAdmin\Template;
810
use PhpMyAdmin\VersionInformation;
911

1012
use function json_encode;
@@ -14,6 +16,15 @@
1416
*/
1517
class VersionCheckController extends AbstractController
1618
{
19+
/** @var VersionInformation */
20+
private $versionInformation;
21+
22+
public function __construct(ResponseRenderer $response, Template $template, VersionInformation $versionInformation)
23+
{
24+
parent::__construct($response, $template);
25+
$this->versionInformation = $versionInformation;
26+
}
27+
1728
public function __invoke(): void
1829
{
1930
$_GET['ajax_request'] = 'true';
@@ -24,16 +35,15 @@ public function __invoke(): void
2435
// Always send the correct headers
2536
Core::headerJSON();
2637

27-
$versionInformation = new VersionInformation();
28-
$versionDetails = $versionInformation->getLatestVersion();
38+
$versionDetails = $this->versionInformation->getLatestVersion();
2939

3040
if (empty($versionDetails)) {
3141
echo json_encode([]);
3242

3343
return;
3444
}
3545

36-
$latestCompatible = $versionInformation->getLatestCompatibleVersion($versionDetails->releases);
46+
$latestCompatible = $this->versionInformation->getLatestCompatibleVersion($versionDetails->releases);
3747
$version = '';
3848
$date = '';
3949
if ($latestCompatible != null) {

libraries/services.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@
239239
'user_preferences' => [
240240
'class' => PhpMyAdmin\UserPreferences::class,
241241
],
242+
'version_information' => [
243+
'class' => PhpMyAdmin\VersionInformation::class,
244+
],
242245
PhpMyAdmin\DatabaseInterface::class => 'dbi',
243246
PhpMyAdmin\FlashMessages::class => 'flash',
244247
PhpMyAdmin\ResponseRenderer::class => 'response',

libraries/services_controllers.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,7 @@
15691569
'arguments' => [
15701570
'$response' => '@response',
15711571
'$template' => '@template',
1572+
'$versionInformation' => '@version_information',
15721573
],
15731574
],
15741575
View\CreateController::class => [

test/classes/Controllers/VersionCheckControllerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpMyAdmin\Template;
99
use PhpMyAdmin\Tests\AbstractTestCase;
1010
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
11+
use PhpMyAdmin\VersionInformation;
1112

1213
use function json_encode;
1314
use function time;
@@ -47,7 +48,7 @@ public function testInvoke(): void
4748
'timestamp' => time(),
4849
];
4950

50-
(new VersionCheckController(new ResponseRenderer(), new Template()))();
51+
(new VersionCheckController(new ResponseRenderer(), new Template(), new VersionInformation()))();
5152

5253
$output = $this->getActualOutputForAssertion();
5354
$this->assertTrue(isset($_GET['ajax_request']));

0 commit comments

Comments
 (0)