‪TYPO3CMS  ‪main
SystemInformationToolbarItem.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\EventDispatcher\EventDispatcherInterface;
21 use Psr\Http\Message\ServerRequestInterface;
34 
40 {
41  private ServerRequestInterface ‪$request;
42  protected array ‪$systemInformation = [];
44  protected string ‪$severityBadgeClass = '';
45  protected array ‪$systemMessages = [];
46  protected int ‪$systemMessageTotalCount = 0;
47 
48  public function ‪__construct(
49  private readonly EventDispatcherInterface $eventDispatcher,
50  private readonly ‪Typo3Version $typo3Version,
51  private readonly ‪BackendViewFactory $backendViewFactory,
52  ) {
54  }
55 
56  public function ‪setRequest(ServerRequestInterface ‪$request): void
57  {
58  $this->request = ‪$request;
59  }
60 
71  public function ‪addSystemMessage($text, $status = ‪InformationStatus::STATUS_OK, $count = 0, $module = '', $params = ''): void
72  {
73  $this->systemMessageTotalCount += (int)$count;
74  $messageSeverity = ‪InformationStatus::cast($status);
75  // define the severity for the badge
76  if ($messageSeverity->isGreaterThan($this->highestSeverity)) {
77  $this->highestSeverity = $messageSeverity;
78  }
79  $this->systemMessages[] = [
80  'module' => $module,
81  'params' => $params,
82  'count' => (int)$count,
83  'status' => $messageSeverity,
84  'text' => $text,
85  ];
86  }
87 
97  public function ‪addSystemInformation($title, $value, $iconIdentifier, $status = ‪InformationStatus::STATUS_NOTICE): void
98  {
99  $this->systemInformation[] = [
100  'title' => $title,
101  'value' => $value,
102  'iconIdentifier' => $iconIdentifier,
103  'status' => $status,
104  ];
105  }
106 
110  public function ‪checkAccess(): bool
111  {
112  return $this->‪getBackendUserAuthentication()->isAdmin();
113  }
114 
118  public function ‪getItem(): string
119  {
120  $view = $this->backendViewFactory->create($this->request);
121  return $view->render('ToolbarItems/SystemInformationToolbarItem');
122  }
123 
127  public function ‪getDropDown(): string
128  {
129  if (!$this->‪checkAccess()) {
130  return '';
131  }
132  $this->‪collectInformation();
133  $view = $this->backendViewFactory->create($this->request);
134  $view->assignMultiple([
135  'messages' => $this->systemMessages,
136  'count' => $this->systemMessageTotalCount > 99 ? '99+' : $this->systemMessageTotalCount,
137  'severityBadgeClass' => $this->severityBadgeClass,
138  'systemInformation' => $this->systemInformation,
139  ]);
140  return $view->render('ToolbarItems/SystemInformationDropDown');
141  }
142 
146  public function ‪getAdditionalAttributes(): array
147  {
148  return [];
149  }
150 
154  public function ‪hasDropDown(): bool
155  {
156  return true;
157  }
158 
162  public function ‪getIndex(): int
163  {
164  return 75;
165  }
166 
170  protected function ‪collectInformation(): void
171  {
172  $this->‪addTypo3Version();
173  $this->‪addWebServer();
174  $this->‪addPhpVersion();
175  $this->‪addDebugger();
176  $this->‪addDatabase();
177  $this->‪addApplicationContext();
178  $this->‪addComposerMode();
179  $this->‪addGitRevision();
180  $this->‪addOperatingSystem();
181  $this->eventDispatcher->dispatch(new ‪SystemInformationToolbarCollectorEvent($this));
182  $this->severityBadgeClass = !$this->highestSeverity->equals(‪InformationStatus::STATUS_NOTICE) ? 'badge-' . (string)$this->highestSeverity : '';
183  }
184 
185  protected function ‪addTypo3Version(): void
186  {
187  $this->systemInformation[] = [
188  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.typo3-version',
189  'value' => $this->typo3Version->getVersion(),
190  'iconIdentifier' => 'information-typo3-version',
191  ];
192  }
193 
194  protected function ‪addWebServer(): void
195  {
196  $this->systemInformation[] = [
197  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.webserver',
198  'value' => $_SERVER['SERVER_SOFTWARE'] ?? '',
199  'iconIdentifier' => 'information-webserver',
200  ];
201  }
202 
203  protected function ‪addPhpVersion(): void
204  {
205  $this->systemInformation[] = [
206  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.phpversion',
207  'value' => PHP_VERSION,
208  'iconIdentifier' => 'information-php-version',
209  ];
210  }
211 
212  protected function ‪addDebugger(): void
213  {
214  $knownDebuggers = ['xdebug', 'Zend Debugger'];
215  foreach ($knownDebuggers as $debugger) {
216  if (extension_loaded($debugger)) {
217  $debuggerVersion = phpversion($debugger) ?: '';
218  $this->systemInformation[] = [
219  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.debugger',
220  'value' => sprintf('%s %s', $debugger, $debuggerVersion),
221  'iconIdentifier' => 'information-debugger',
222  ];
223  }
224  }
225  }
226 
227  protected function ‪addDatabase(): void
228  {
229  foreach (GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionNames() as $connectionName) {
230  $serverVersion = '[' . $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.database.offline') . ']';
231  $success = true;
232  try {
233  $serverVersion = GeneralUtility::makeInstance(ConnectionPool::class)
234  ->getConnectionByName($connectionName)
235  ->getServerVersion();
236  } catch (\‪Exception $exception) {
237  $success = false;
238  }
239  $this->systemInformation[] = [
240  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.database',
241  'titleAddition' => $connectionName,
242  'value' => $serverVersion,
243  'status' => $success ?: ‪InformationStatus::STATUS_WARNING,
244  'iconIdentifier' => 'information-database',
245  ];
246  }
247  }
248 
249  protected function ‪addApplicationContext(): void
250  {
251  $applicationContext = ‪Environment::getContext();
252  $this->systemInformation[] = [
253  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.applicationcontext',
254  'value' => (string)$applicationContext,
255  'status' => $applicationContext->isProduction() ? ‪InformationStatus::STATUS_OK : ‪InformationStatus::STATUS_WARNING,
256  'iconIdentifier' => 'information-application-context',
257  ];
258  }
259 
263  protected function ‪addComposerMode(): void
264  {
266  return;
267  }
268  $this->systemInformation[] = [
269  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.composerMode',
270  'value' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.enabled'),
271  'iconIdentifier' => 'information-composer-mode',
272  ];
273  }
274 
278  protected function ‪addGitRevision(): void
279  {
280  if (!str_ends_with($this->typo3Version->getVersion(), '-dev') || $this->isFunctionDisabled('exec')) {
281  return;
282  }
283  // check if git exists
284  $returnCode = 0;
285  ‪CommandUtility::exec('git --version', $_, $returnCode);
286  if ($returnCode !== 0) {
287  // git is not available
288  return;
289  }
290 
291  $revision = trim(‪CommandUtility::exec('git rev-parse --short HEAD'));
292  $branch = trim(‪CommandUtility::exec('git rev-parse --abbrev-ref HEAD'));
293  if (!empty($revision) && !empty($branch)) {
294  $this->systemInformation[] = [
295  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.gitrevision',
296  'value' => sprintf('%s [%s]', $revision, $branch),
297  'iconIdentifier' => 'information-git',
298  ];
299  }
300  }
301 
305  protected function ‪addOperatingSystem(): void
306  {
307  switch (PHP_OS_FAMILY) {
308  case 'Linux':
309  $icon = 'linux';
310  break;
311  case 'Darwin':
312  $icon = 'apple';
313  break;
314  case 'Windows':
315  $icon = 'windows';
316  break;
317  default:
318  $icon = 'unknown';
319  }
320  $this->systemInformation[] = [
321  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.operatingsystem',
322  'value' => PHP_OS . ' ' . php_uname('r'),
323  'iconIdentifier' => 'information-os-' . $icon,
324  ];
325  }
326 
330  protected function ‪isFunctionDisabled(string $functionName): bool
331  {
332  $disabledFunctions = GeneralUtility::trimExplode(',', (string)ini_get('disable_functions'));
333  if (!empty($disabledFunctions)) {
334  return in_array($functionName, $disabledFunctions, true);
335  }
336  return false;
337  }
338 
340  {
341  return ‪$GLOBALS['BE_USER'];
342  }
343 
345  {
346  return ‪$GLOBALS['LANG'];
347  }
348 }
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus\STATUS_INFO
‪const STATUS_INFO
Definition: InformationStatus.php:35
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getIndex
‪getIndex()
Definition: SystemInformationToolbarItem.php:162
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$highestSeverity
‪InformationStatus $highestSeverity
Definition: SystemInformationToolbarItem.php:43
‪TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface
Definition: ToolbarItemInterface.php:22
‪TYPO3\CMS\Core\Information\Typo3Version
Definition: Typo3Version.php:21
‪TYPO3\CMS\Backend\View\BackendViewFactory
Definition: BackendViewFactory.php:35
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addDebugger
‪addDebugger()
Definition: SystemInformationToolbarItem.php:212
‪TYPO3\CMS\Backend\Backend\Event\SystemInformationToolbarCollectorEvent
Definition: SystemInformationToolbarCollectorEvent.php:27
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static isComposerMode()
Definition: Environment.php:137
‪TYPO3\CMS\Backend\Exception
Definition: Exception.php:24
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getItem
‪getItem()
Definition: SystemInformationToolbarItem.php:118
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addTypo3Version
‪addTypo3Version()
Definition: SystemInformationToolbarItem.php:185
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addPhpVersion
‪addPhpVersion()
Definition: SystemInformationToolbarItem.php:203
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\isFunctionDisabled
‪isFunctionDisabled(string $functionName)
Definition: SystemInformationToolbarItem.php:330
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addWebServer
‪addWebServer()
Definition: SystemInformationToolbarItem.php:194
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus\STATUS_OK
‪const STATUS_OK
Definition: InformationStatus.php:40
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$systemMessages
‪array $systemMessages
Definition: SystemInformationToolbarItem.php:45
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:186
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$severityBadgeClass
‪string $severityBadgeClass
Definition: SystemInformationToolbarItem.php:44
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getBackendUserAuthentication
‪getBackendUserAuthentication()
Definition: SystemInformationToolbarItem.php:339
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus\STATUS_WARNING
‪const STATUS_WARNING
Definition: InformationStatus.php:45
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getLanguageService
‪getLanguageService()
Definition: SystemInformationToolbarItem.php:344
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addComposerMode
‪addComposerMode()
Definition: SystemInformationToolbarItem.php:263
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getDropDown
‪getDropDown()
Definition: SystemInformationToolbarItem.php:127
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addGitRevision
‪addGitRevision()
Definition: SystemInformationToolbarItem.php:278
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\collectInformation
‪collectInformation()
Definition: SystemInformationToolbarItem.php:170
‪TYPO3\CMS\Backend\Backend\ToolbarItems
Definition: ClearCacheToolbarItem.php:18
‪TYPO3\CMS\Core\Utility\CommandUtility\exec
‪static exec(string $command, ?array &$output=null, int &$returnValue=0)
Definition: CommandUtility.php:85
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem
Definition: SystemInformationToolbarItem.php:40
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$systemMessageTotalCount
‪int $systemMessageTotalCount
Definition: SystemInformationToolbarItem.php:46
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addOperatingSystem
‪addOperatingSystem()
Definition: SystemInformationToolbarItem.php:305
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\__construct
‪__construct(private readonly EventDispatcherInterface $eventDispatcher, private readonly Typo3Version $typo3Version, private readonly BackendViewFactory $backendViewFactory,)
Definition: SystemInformationToolbarItem.php:48
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$systemInformation
‪array $systemInformation
Definition: SystemInformationToolbarItem.php:42
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:64
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\hasDropDown
‪hasDropDown()
Definition: SystemInformationToolbarItem.php:154
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus
Definition: InformationStatus.php:24
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addSystemInformation
‪addSystemInformation($title, $value, $iconIdentifier, $status=InformationStatus::STATUS_NOTICE)
Definition: SystemInformationToolbarItem.php:97
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addDatabase
‪addDatabase()
Definition: SystemInformationToolbarItem.php:227
‪TYPO3\CMS\Backend\Toolbar\RequestAwareToolbarItemInterface
Definition: RequestAwareToolbarItemInterface.php:27
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addApplicationContext
‪addApplicationContext()
Definition: SystemInformationToolbarItem.php:249
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\setRequest
‪setRequest(ServerRequestInterface $request)
Definition: SystemInformationToolbarItem.php:56
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$request
‪ServerRequestInterface $request
Definition: SystemInformationToolbarItem.php:41
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addSystemMessage
‪addSystemMessage($text, $status=InformationStatus::STATUS_OK, $count=0, $module='', $params='')
Definition: SystemInformationToolbarItem.php:71
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getAdditionalAttributes
‪getAdditionalAttributes()
Definition: SystemInformationToolbarItem.php:146
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:51
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Utility\CommandUtility
Definition: CommandUtility.php:54
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\checkAccess
‪checkAccess()
Definition: SystemInformationToolbarItem.php:110
‪TYPO3\CMS\Core\Core\Environment\getContext
‪static getContext()
Definition: Environment.php:128
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus\STATUS_NOTICE
‪const STATUS_NOTICE
Definition: InformationStatus.php:30