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