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
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';
36 * @see fastcgi_finish_request
38 public function hasFastCgi(): bool {
39 return function_exists( 'fastcgi_finish_request' );
43 * @see fastcgi_finish_request
45 public function fastCgiFinishRequest(): bool {
46 if ( $this->hasFastCgi() ) {
47 return fastcgi_finish_request();
52 public function getServerInfo( string $key, $default = null ) {
53 return $_SERVER[$key] ??
$default;
61 public function exit( int $code = 0 ) {
65 public function disableModDeflate(): void
{
66 if ( function_exists( 'apache_setenv' ) ) {
67 // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
76 * Triggers a PHP runtime error
80 public function triggerError( string $message, int $level = E_USER_NOTICE
): bool {
81 return trigger_error( $message, $level );
85 * Returns the value of an environment variable.
91 * @return array|false|string
93 public function getEnv( string $name ) {
94 return getenv( $name );
98 * Returns the value of an ini option.
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 );