ILIAS  release_8 Revision v8.24
class.ilRuntime.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26final class ilRuntime
27{
28 private static ?self $instance = null;
29
33 private function __construct()
34 {
35 }
36
37 public static function getInstance(): self
38 {
39 if (self::$instance === null) {
40 self::$instance = new self();
41 }
42
43 return self::$instance;
44 }
45
46 public function isHHVM(): bool
47 {
48 return defined('HHVM_VERSION');
49 }
50
51 public function isPHP(): bool
52 {
53 return !$this->isHHVM();
54 }
55
56 public function isFPM(): bool
57 {
58 return PHP_SAPI === 'fpm-fcgi';
59 }
60
61 public function getVersion(): string
62 {
63 if ($this->isHHVM()) {
64 return HHVM_VERSION;
65 }
66
67 return PHP_VERSION;
68 }
69
70 public function getName(): string
71 {
72 if ($this->isHHVM()) {
73 return 'HHVM';
74 }
75
76 return 'PHP';
77 }
78
79 public function __toString(): string
80 {
81 return $this->getName() . ' ' . $this->getVersion();
82 }
83
84 public function getReportedErrorLevels(): int
85 {
86 if ($this->isHHVM()) {
87 return (int) ini_get('hhvm.log.runtime_error_reporting_level');
88 }
89
90 return (int) ini_get('error_reporting');
91 }
92
93 public function shouldLogErrors(): bool
94 {
95 if ($this->isHHVM()) {
96 return (bool) ini_get('hhvm.log.use_log_file');
97 }
98
99 return (bool) ini_get('log_errors');
100 }
101
102 public function shouldDisplayErrors(): bool
103 {
104 if ($this->isHHVM()) {
105 return (bool) ini_get('hhvm.debug.server_error_message');
106 }
107
108 return (bool) ini_get('display_errors');
109 }
110
111 public function getBinary(): string
112 {
113 if (defined('PHP_BINARY') && PHP_BINARY !== '') {
114 return escapeshellarg(PHP_BINARY);
115 }
116
117 $possibleBinaryLocations = [
118 PHP_BINDIR . '/php',
119 PHP_BINDIR . '/php-cli.exe',
120 PHP_BINDIR . '/php.exe',
121 ];
122
123 foreach ($possibleBinaryLocations as $binary) {
124 if (is_readable($binary)) {
125 return escapeshellarg($binary);
126 }
127 }
128
129 return 'php';
130 }
131}
__construct()
The runtime is a constant state during one request, so please use the public static getInstance() to ...
static self $instance
getReportedErrorLevels()
static getInstance()