ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilGitInformation.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
30 private static ?array $revision_information = null;
31
32 private static function detect(): void
33 {
34 global $DIC;
35
36 $lng = $DIC->language();
37
38 if (null !== self::$revision_information) {
39 return;
40 }
41
42 $info = array();
43
44 if (!ilUtil::isWindows()) {
45 $origin = ilShellUtil::execQuoted('git config --get remote.origin.url');
46 $branch = ilShellUtil::execQuoted('git rev-parse --abbrev-ref HEAD');
47 $version_mini_hash = ilShellUtil::execQuoted('git rev-parse --short HEAD');
48 $version_number = ilShellUtil::execQuoted('git rev-list --count HEAD');
49 $line = ilShellUtil::execQuoted('git log -1');
50
51 if (!empty($origin[0])) {
52 $origin = $origin[0];
53 }
54
55 if (!empty($branch[0])) {
56 $branch = $branch[0];
57 }
58
59 if (!empty($version_number[0])) {
60 $version_number = $version_number[0];
61 }
62
63 if (!empty($version_mini_hash[0])) {
64 $version_mini_hash = $version_mini_hash[0];
65 }
66
67 if ($line && array_filter($line)) {
68 $line = implode(' | ', array_filter($line));
69 }
70 } else {
71 $origin = trim(exec('git config --get remote.origin.url'));
72 $branch = trim(exec('git rev-parse --abbrev-ref HEAD'));
73 $version_mini_hash = trim(exec('git rev-parse --short HEAD'));
74 $version_number = exec('git rev-list --count HEAD');
75 $line = trim(exec('git log -1'));
76 }
77
78 if ($origin) {
79 $info[] = $origin;
80 }
81
82 if ($branch) {
83 $info[] = $branch;
84 }
85
86 if ($version_number) {
87 $info[] = sprintf($lng->txt('git_revision'), $version_number);
88 }
89
90 if ($version_mini_hash) {
91 $info[] = sprintf($lng->txt('git_hash_short'), $version_mini_hash);
92 }
93
94 if ($line) {
95 $info[] = sprintf($lng->txt('git_last_commit'), $line);
96 }
97
98 self::$revision_information = $info;
99 }
100
101 public function getInformationAsHtml(): string
102 {
103 self::detect();
104
105 return implode("<br />", self::$revision_information);
106 }
107}
Class ilGitInformation.
static array $revision_information
static execQuoted(string $cmd, ?string $args=null)
static isWindows()
$info
Definition: entry_point.php:21
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26