Sapi.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Pimf
  4. *
  5. * @copyright Copyright (c) Gjero Krsteski (http://krsteski.de)
  6. * @license http://krsteski.de/new-bsd-license New BSD License
  7. */
  8. namespace Pimf;
  9. /**
  10. * Handles the type of interface between web server and PHP
  11. *
  12. * @package Pimf
  13. * @author Gjero Krsteski <[email protected]>
  14. */
  15. abstract class Sapi
  16. {
  17. /**
  18. * Are we in a web environment?
  19. *
  20. * @return boolean
  21. */
  22. public static function isWeb()
  23. {
  24. return self::isApache() || self::isIIS() || self::isCgi();
  25. }
  26. /**
  27. * Are we in a cli environment?
  28. *
  29. * @return boolean
  30. */
  31. public static function isCli()
  32. {
  33. return PHP_SAPI === 'cli';
  34. }
  35. /**
  36. * Are we in a cgi environment?
  37. *
  38. * @return boolean
  39. */
  40. public static function isCgi()
  41. {
  42. return PHP_SAPI === 'cgi-fcgi' || PHP_SAPI === 'cgi';
  43. }
  44. /**
  45. * Are we served through Apache[2]?
  46. *
  47. * @return boolean
  48. */
  49. public static function isApache()
  50. {
  51. return PHP_SAPI === 'apache2handler' || PHP_SAPI === 'apachehandler';
  52. }
  53. /**
  54. * Are we served through IIS?
  55. *
  56. * @return boolean
  57. */
  58. public static function isIIS()
  59. {
  60. return PHP_SAPI == 'isapi';
  61. }
  62. /**
  63. * @return bool
  64. */
  65. public static function isWindows()
  66. {
  67. return (boolean)(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
  68. }
  69. }