SystemFactory.php 843 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace League\CLImate\Util\System;
  3. class SystemFactory
  4. {
  5. /**
  6. * @var \League\CLImate\Util\System\System $instance
  7. */
  8. protected static $instance;
  9. /**
  10. * Get an instance of the appropriate System class
  11. *
  12. * @return \League\CLImate\Util\System\System
  13. */
  14. public static function getInstance()
  15. {
  16. if (static::$instance) {
  17. return static::$instance;
  18. }
  19. static::$instance = self::getSystem();
  20. return static::$instance;
  21. }
  22. /**
  23. * Set the $instance property to the appropriate system
  24. *
  25. * @return \League\CLImate\Util\System\System
  26. */
  27. protected static function getSystem()
  28. {
  29. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  30. return new Windows();
  31. }
  32. return new Linux();
  33. }
  34. }