-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathGitInfoController.php
More file actions
50 lines (37 loc) · 1.35 KB
/
GitInfoController.php
File metadata and controls
50 lines (37 loc) · 1.35 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
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers;
use DateTimeImmutable;
use PhpMyAdmin\Config;
use PhpMyAdmin\Git;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing\Route;
use PhpMyAdmin\Util;
#[Route('/git-revision', ['GET', 'POST'])]
final readonly class GitInfoController implements InvocableController
{
public function __construct(private ResponseRenderer $response, private Config $config)
{
}
public function __invoke(ServerRequest $request): Response
{
if (! $request->isAjax()) {
return $this->response->response();
}
$git = new Git($this->config->config->ShowGitRevision);
if (! $git->isGitRevision()) {
return $this->response->response();
}
$commit = $git->checkGitRevision();
if (! $git->hasGitInformation() || $commit === null) {
$this->response->setRequestStatus(false);
return $this->response->response();
}
$commit['author']['date'] = Util::localisedDate(new DateTimeImmutable($commit['author']['date']));
$commit['committer']['date'] = Util::localisedDate(new DateTimeImmutable($commit['committer']['date']));
$this->response->render('home/git_info', $commit);
return $this->response->response();
}
}