Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
EntryPointEnvironment | |
0.00% |
0 / 16 |
|
0.00% |
0 / 10 |
182 | |
0.00% |
0 / 1 |
isCli | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
hasFastCgi | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
fastCgiFinishRequest | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getServerInfo | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
exit | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
disableModDeflate | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
triggerError | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getEnv | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getIni | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setIniOption | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki; |
22 | |
23 | /** |
24 | * Utility class wrapping PHP runtime state. |
25 | * |
26 | * @internal For use by MediaWikiEntryPoint subclasses. |
27 | * Should be revised before wider use. |
28 | */ |
29 | class EntryPointEnvironment { |
30 | |
31 | public function isCli(): bool { |
32 | return PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg'; |
33 | } |
34 | |
35 | /** |
36 | * @see fastcgi_finish_request |
37 | */ |
38 | public function hasFastCgi(): bool { |
39 | return function_exists( 'fastcgi_finish_request' ); |
40 | } |
41 | |
42 | /** |
43 | * @see fastcgi_finish_request |
44 | */ |
45 | public function fastCgiFinishRequest(): bool { |
46 | if ( $this->hasFastCgi() ) { |
47 | return fastcgi_finish_request(); |
48 | } |
49 | return false; |
50 | } |
51 | |
52 | public function getServerInfo( string $key, $default = null ) { |
53 | return $_SERVER[$key] ?? $default; |
54 | } |
55 | |
56 | /** |
57 | * @param int $code |
58 | * |
59 | * @return never |
60 | */ |
61 | public function exit( int $code = 0 ) { |
62 | exit( $code ); |
63 | } |
64 | |
65 | public function disableModDeflate(): void { |
66 | if ( function_exists( 'apache_setenv' ) ) { |
67 | // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged |
68 | @apache_setenv( |
69 | 'no-gzip', |
70 | '1' |
71 | ); |
72 | } |
73 | } |
74 | |
75 | /** |
76 | * Triggers a PHP runtime error |
77 | * |
78 | * @see trigger_error |
79 | */ |
80 | public function triggerError( string $message, int $level = E_USER_NOTICE ): bool { |
81 | return trigger_error( $message, $level ); |
82 | } |
83 | |
84 | /** |
85 | * Returns the value of an environment variable. |
86 | * |
87 | * @see getenv |
88 | * |
89 | * @param string $name |
90 | * |
91 | * @return array|false|string |
92 | */ |
93 | public function getEnv( string $name ) { |
94 | return getenv( $name ); |
95 | } |
96 | |
97 | /** |
98 | * Returns the value of an ini option. |
99 | * |
100 | * @see ini_get |
101 | * |
102 | * @param string $name |
103 | * |
104 | * @return false|string |
105 | */ |
106 | public function getIni( string $name ) { |
107 | return ini_get( $name ); |
108 | } |
109 | |
110 | /** |
111 | * @param string $name |
112 | * @param mixed $value |
113 | * |
114 | * @return false|string |
115 | */ |
116 | public function setIniOption( string $name, $value ) { |
117 | return ini_set( $name, $value ); |
118 | } |
119 | |
120 | } |