Translated using Weblate (Portuguese)
[phpmyadmin.git] / src / Server / SysInfo / SysInfo.php
blobae0e27742466d925e1c9dc207290f3818d75ee44
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Server\SysInfo;
7 use function in_array;
8 use function ucfirst;
10 use const PHP_OS;
12 /**
13 * Library for extracting information about system memory and cpu.
14 * Currently supports all Windows and Linux platforms
16 * This code is based on the OS Classes from the phpsysinfo project
17 * (https://phpsysinfo.github.io/phpsysinfo/)
19 class SysInfo
21 public const MEMORY_REGEXP = '/^(MemTotal|MemFree|Cached|Buffers|SwapCached|SwapTotal|SwapFree):\s+(.*)\s*kB/im';
23 /**
24 * Returns OS type used for sysinfo class
26 * @param string $phpOs PHP_OS constant
28 public static function getOs(string $phpOs = PHP_OS): string
30 // look for common UNIX-like systems
31 if (in_array($phpOs, ['FreeBSD', 'DragonFly'], true)) {
32 return 'Linux';
35 return ucfirst($phpOs);
38 /**
39 * Gets SysInfo class matching current OS
41 * @return Base sysinfo class
43 public static function get(): Base
45 $phpOs = self::getOs();
47 switch ($phpOs) {
48 case 'Linux':
49 if (Linux::isSupported()) {
50 return new Linux();
53 break;
54 case 'WINNT':
55 if (WindowsNt::isSupported()) {
56 return new WindowsNt();
59 break;
60 case 'SunOS':
61 if (SunOs::isSupported()) {
62 return new SunOs();
65 break;
68 return new Base();