|
17 | 17 |
|
18 | 18 | ob_start(); // Start output buffering to ensure headers can be sent later. |
19 | 19 |
|
20 | | -/** |
21 | | - * Define the directory separator constant. |
22 | | - * |
23 | | - * This ensures platform-independent path building. |
24 | | - */ |
25 | | -define('DS', DIRECTORY_SEPARATOR); |
26 | | - |
27 | 20 | /** |
28 | 21 | * ------------------------------------------------------------------------ |
29 | 22 | * Application Bootstrapping Closure |
|
36 | 29 | * - Configures PHP error reporting |
37 | 30 | * - Ensures compatibility with CLI and web server |
38 | 31 | */ |
39 | | -(static function (): void { |
| 32 | +(function () { |
40 | 33 |
|
41 | 34 | /** |
42 | 35 | * Normalize working directory for CLI. |
|
64 | 57 | * |
65 | 58 | * @throws RuntimeException if the path is invalid. |
66 | 59 | */ |
67 | | - $resolve = static function (string $path, string $name = ''): string { |
| 60 | + $resolve = function ($path, $name = '') { |
68 | 61 | // Try resolving to absolute path |
69 | 62 | if (($real = realpath($path)) !== false) { |
70 | 63 | return $real; |
71 | 64 | } |
72 | 65 |
|
73 | 66 | // Normalize slashes and check directory existence manually |
74 | | - $real = rtrim(str_replace(['/', '\\'], DS, $path), DS); |
| 67 | + $real = rtrim(str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path), DIRECTORY_SEPARATOR); |
75 | 68 | if (is_dir($real)) { |
76 | 69 | return $real; |
77 | 70 | } |
|
97 | 90 | */ |
98 | 91 |
|
99 | 92 | // Path to this front controller (index.php) |
100 | | - define('FCPATH', __DIR__.DS); |
| 93 | + define('FCPATH', __DIR__.DIRECTORY_SEPARATOR); |
101 | 94 |
|
102 | 95 | // Path to CiSkeleton system folder |
103 | | - define('BASEPATH', $resolve('skeleton', 'system').DS); |
| 96 | + define('BASEPATH', $resolve('skeleton', 'system').DIRECTORY_SEPARATOR); |
104 | 97 |
|
105 | 98 | // Path to the application folder |
106 | | - define('APPPATH', $resolve('application', 'application').DS); |
| 99 | + define('APPPATH', $resolve('application', 'application').DIRECTORY_SEPARATOR); |
107 | 100 |
|
108 | 101 | // The name of the "system" folder (used internally) |
109 | 102 | define('SYSDIR', basename(BASEPATH)); |
110 | | - |
111 | | - // -------------------------------------------------------------------- |
112 | | - // ENVIRONMENT SETUP |
113 | | - // -------------------------------------------------------------------- |
114 | | - |
115 | | - /** |
116 | | - * Environment file path (APPPATH/config/environment) |
117 | | - * |
118 | | - * This file should contain a single line: "development", "testing", or "production". |
119 | | - */ |
120 | | - $envfile = APPPATH.'config'.DS.'environment'; |
121 | | - |
122 | | - /** |
123 | | - * Default to "development" if file does not exist. |
124 | | - * Also create the file with the default value. |
125 | | - */ |
126 | | - if (!is_file($envfile)) { |
127 | | - $environment = 'development'; |
128 | | - file_put_contents($envfile, $environment, LOCK_EX); |
129 | | - } else { |
130 | | - $environment = trim(file_get_contents($envfile)); |
131 | | - } |
132 | | - |
133 | | - /** |
134 | | - * Fallback if file contents are invalid. |
135 | | - * Only the three official environments are allowed. |
136 | | - */ |
137 | | - if (!in_array($environment, ['development', 'testing', 'production'], true)) { |
138 | | - $environment = 'development'; |
139 | | - file_put_contents($envfile, $environment, LOCK_EX); |
140 | | - } |
141 | | - |
142 | | - /** |
143 | | - * Define the ENVIRONMENT constant. |
144 | | - */ |
145 | | - define('ENVIRONMENT', $environment); |
146 | | - |
147 | | - /** |
148 | | - * Set PHP error reporting levels based on ENVIRONMENT. |
149 | | - * |
150 | | - * You may customize this if you add more environments. |
151 | | - */ |
152 | | - switch (ENVIRONMENT) { |
153 | | - case 'development': |
154 | | - case 'testing': |
155 | | - // Show all errors, including strict and deprecated |
156 | | - error_reporting(E_ALL); |
157 | | - ini_set('display_errors', '1'); |
158 | | - ini_set('log_errors', '1'); |
159 | | - ini_set('error_log', APPPATH.'storage/logs/php_errors.log'); |
160 | | - |
161 | | - define('SHOW_DEBUG_BACKTRACE', true); |
162 | | - define('CI_DEBUG', true); |
163 | | - break; |
164 | | - |
165 | | - case 'production': |
166 | | - if (PHP_SAPI === 'cli' || defined('STDIN')) { |
167 | | - // In CLI mode, we want full error visibility even in production |
168 | | - error_reporting(E_ALL); |
169 | | - ini_set('display_errors', '1'); |
170 | | - } else { |
171 | | - // Suppress errors on the web frontend |
172 | | - error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE); |
173 | | - ini_set('display_errors', '0'); |
174 | | - } |
175 | | - |
176 | | - // Always log errors in production (CLI or Web) |
177 | | - ini_set('log_errors', '1'); |
178 | | - ini_set('error_log', APPPATH.'storage/logs/php_errors.log'); |
179 | | - |
180 | | - define('SHOW_DEBUG_BACKTRACE', false); |
181 | | - define('CI_DEBUG', false); |
182 | | - break; |
183 | | - |
184 | | - default: |
185 | | - // This should never happen because we validated earlier |
186 | | - header('HTTP/1.1 503 Service Unavailable.', true, 503); |
187 | | - echo 'The application environment is not set correctly.'; |
188 | | - exit(1); // EXIT_ERROR |
189 | | - } |
190 | | - |
191 | 103 | })(); // <-- END of bootstrapping closure |
192 | 104 |
|
193 | 105 | /** |
|
0 commit comments