ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilRuntime.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21final 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}
__construct()
The runtime is a constant state during one request, so please use the public static getInstance() to ...
static self $instance
getReportedErrorLevels()
static getInstance()