|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Pimf |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) Gjero Krsteski (http://krsteski.de) |
|
6
|
|
|
* @license http://opensource.org/licenses/MIT MIT License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Pimf; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Handles the type of interface between web server and PHP |
|
13
|
|
|
* |
|
14
|
|
|
* @package Pimf |
|
15
|
|
|
* @author Gjero Krsteski <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
abstract class Sapi |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Are we in a web environment? |
|
22
|
|
|
* |
|
23
|
|
|
* @return boolean |
|
24
|
|
|
*/ |
|
25
|
|
|
public static function isWeb() |
|
26
|
|
|
{ |
|
27
|
|
|
return self::isApache() || self::isIIS() || self::isCgi() || self::isBuiltInWebServer() || self::isHHVM(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Are we in a cli environment? |
|
32
|
|
|
* |
|
33
|
|
|
* @return boolean |
|
34
|
|
|
*/ |
|
35
|
|
|
public static function isCli() |
|
36
|
|
|
{ |
|
37
|
|
|
return PHP_SAPI === 'cli'; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Are we in a cgi environment? |
|
42
|
|
|
* |
|
43
|
|
|
* @return boolean |
|
44
|
|
|
*/ |
|
45
|
|
|
public static function isCgi() |
|
46
|
|
|
{ |
|
47
|
|
|
return PHP_SAPI === 'cgi-fcgi' || PHP_SAPI === 'cgi'; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Are we served through Apache[2]? |
|
52
|
|
|
* |
|
53
|
|
|
* @return boolean |
|
54
|
|
|
*/ |
|
55
|
|
|
public static function isApache() |
|
56
|
|
|
{ |
|
57
|
|
|
return PHP_SAPI === 'apache2handler' || PHP_SAPI === 'apachehandler'; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Are we served through IIS? |
|
62
|
|
|
* |
|
63
|
|
|
* @return boolean |
|
64
|
|
|
*/ |
|
65
|
|
|
public static function isIIS() |
|
66
|
|
|
{ |
|
67
|
|
|
return PHP_SAPI == 'isapi'; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Are we served through PHP's built-in web server. |
|
72
|
|
|
* |
|
73
|
|
|
* @return bool |
|
74
|
|
|
*/ |
|
75
|
|
|
public static function isBuiltInWebServer() |
|
76
|
|
|
{ |
|
77
|
|
|
return PHP_SAPI == 'cli-server'; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Are we served through HHVM virtual machine |
|
82
|
|
|
* |
|
83
|
|
|
* @return bool |
|
84
|
|
|
*/ |
|
85
|
|
|
public static function isHHVM() |
|
86
|
|
|
{ |
|
87
|
|
|
return PHP_SAPI == 'srv'; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return bool |
|
92
|
|
|
*/ |
|
93
|
|
|
public static function isWindows() |
|
94
|
|
|
{ |
|
95
|
|
|
return (boolean)(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|