Geen omschrijving

OperatingSystem.php 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of sebastian/environment.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\Environment;
  11. final class OperatingSystem
  12. {
  13. /**
  14. * Returns PHP_OS_FAMILY (if defined (which it is on PHP >= 7.2)).
  15. * Returns a string (compatible with PHP_OS_FAMILY) derived from PHP_OS otherwise.
  16. */
  17. public function getFamily(): string
  18. {
  19. if (\defined('PHP_OS_FAMILY')) {
  20. return \PHP_OS_FAMILY;
  21. }
  22. if (\DIRECTORY_SEPARATOR === '\\') {
  23. return 'Windows';
  24. }
  25. switch (\PHP_OS) {
  26. case 'Darwin':
  27. return 'Darwin';
  28. case 'DragonFly':
  29. case 'FreeBSD':
  30. case 'NetBSD':
  31. case 'OpenBSD':
  32. return 'BSD';
  33. case 'Linux':
  34. return 'Linux';
  35. case 'SunOS':
  36. return 'Solaris';
  37. default:
  38. return 'Unknown';
  39. }
  40. }
  41. }