OperatingSystem.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  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. declare(strict_types=1);
  11. namespace SebastianBergmann\Environment;
  12. final class OperatingSystem
  13. {
  14. /**
  15. * Returns PHP_OS_FAMILY (if defined (which it is on PHP >= 7.2)).
  16. * Returns a string (compatible with PHP_OS_FAMILY) derived from PHP_OS otherwise.
  17. */
  18. public function getFamily(): string
  19. {
  20. if (\defined('PHP_OS_FAMILY')) {
  21. return PHP_OS_FAMILY;
  22. }
  23. if (DIRECTORY_SEPARATOR === '\\') {
  24. return 'Windows';
  25. }
  26. switch (PHP_OS) {
  27. case 'Darwin':
  28. return 'Darwin';
  29. case 'DragonFly':
  30. case 'FreeBSD':
  31. case 'NetBSD':
  32. case 'OpenBSD':
  33. return 'BSD';
  34. case 'Linux':
  35. return 'Linux';
  36. case 'SunOS':
  37. return 'Solaris';
  38. default:
  39. return 'Unknown';
  40. }
  41. }
  42. }