SysInfo.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Library for extracting information about system memory and cpu.
  5. * Currently supports all Windows and Linux platforms
  6. *
  7. * This code is based on the OS Classes from the phpsysinfo project
  8. * (https://phpsysinfo.github.io/phpsysinfo/)
  9. *
  10. * @package PhpMyAdmin-sysinfo
  11. */
  12. namespace PhpMyAdmin;
  13. use PhpMyAdmin\SysInfoBase;
  14. /**
  15. * PhpMyAdmin\SysInfo class
  16. *
  17. * @package PhpMyAdmin
  18. */
  19. class SysInfo
  20. {
  21. const MEMORY_REGEXP = '/^(MemTotal|MemFree|Cached|Buffers|SwapCached|SwapTotal|SwapFree):\s+(.*)\s*kB/im';
  22. /**
  23. * Returns OS type used for sysinfo class
  24. *
  25. * @param string $php_os PHP_OS constant
  26. *
  27. * @return string
  28. */
  29. public static function getOs($php_os = PHP_OS)
  30. {
  31. // look for common UNIX-like systems
  32. $unix_like = array('FreeBSD', 'DragonFly');
  33. if (in_array($php_os, $unix_like)) {
  34. $php_os = 'Linux';
  35. }
  36. return ucfirst($php_os);
  37. }
  38. /**
  39. * Gets sysinfo class mathing current OS
  40. *
  41. * @return PhpMyAdmin\SysInfoBase|mixed sysinfo class
  42. */
  43. public static function get()
  44. {
  45. $php_os = self::getOs();
  46. $supported = array('Linux', 'WINNT', 'SunOS');
  47. if (in_array($php_os, $supported)) {
  48. $class_name = 'PhpMyAdmin\SysInfo' . $php_os;
  49. /** @var PhpMyAdmin\SysInfoBase $ret */
  50. $ret = new $class_name();
  51. if ($ret->supported()) {
  52. return $ret;
  53. }
  54. }
  55. return new SysInfoBase();
  56. }
  57. }