Merge "rdbms: Replace func_get_args() in SQLPlatform::buildLike()"
[mediawiki.git] / includes / EntryPointEnvironment.php
blob78ef2869b0bc7d6e09a892339408950699d04d4c
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.
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.
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
18 * @file
21 namespace MediaWiki;
23 /**
24 * Utility class wrapping PHP runtime state.
26 * @internal For use by MediaWikiEntryPoint subclasses.
27 * Should be revised before wider use.
29 class EntryPointEnvironment {
31 public function isCli(): bool {
32 return PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg';
35 /**
36 * @see fastcgi_finish_request
38 public function hasFastCgi(): bool {
39 return function_exists( 'fastcgi_finish_request' );
42 /**
43 * @see fastcgi_finish_request
45 public function fastCgiFinishRequest(): bool {
46 if ( $this->hasFastCgi() ) {
47 return fastcgi_finish_request();
49 return false;
52 public function getServerInfo( string $key, $default = null ) {
53 return $_SERVER[$key] ?? $default;
56 /**
57 * @param int $code
59 * @return never
61 public function exit( int $code = 0 ) {
62 exit( $code );
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'
75 /**
76 * Triggers a PHP runtime error
78 * @see trigger_error
80 public function triggerError( string $message, int $level = E_USER_NOTICE ): bool {
81 return trigger_error( $message, $level );
84 /**
85 * Returns the value of an environment variable.
87 * @see getenv
89 * @param string $name
91 * @return array|false|string
93 public function getEnv( string $name ) {
94 return getenv( $name );
97 /**
98 * Returns the value of an ini option.
100 * @see ini_get
102 * @param string $name
104 * @return false|string
106 public function getIni( string $name ) {
107 return ini_get( $name );
111 * @param string $name
112 * @param mixed $value
114 * @return false|string
116 public function setIniOption( string $name, $value ) {
117 return ini_set( $name, $value );