1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Zemit Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Zemit Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Zemit\Support; |
13
|
|
|
|
14
|
|
|
class Php |
15
|
|
|
{ |
16
|
|
|
public static function isCli(): bool |
17
|
|
|
{ |
18
|
|
|
return PHP_SAPI === 'cli'; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Trust forwarded protocol and force $_SERVER['https'] to 'on' |
23
|
|
|
*/ |
24
|
|
|
public static function trustForwardedProto(): void |
25
|
|
|
{ |
26
|
|
|
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '', 'https') !== false) { |
27
|
|
|
$_SERVER['HTTPS'] = 'on'; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Set debugging values |
33
|
|
|
*/ |
34
|
|
|
public static function debug(?bool $debug = null): void |
35
|
|
|
{ |
36
|
|
|
if ($debug) { |
37
|
|
|
// Enabling error reporting and display |
38
|
|
|
error_reporting(E_ALL); |
39
|
|
|
ini_set('display_startup_errors', '1'); |
40
|
|
|
ini_set('display_errors', '1'); |
41
|
|
|
} else { |
42
|
|
|
// Disabling error reporting and display |
43
|
|
|
error_reporting(-1); |
44
|
|
|
ini_set('display_startup_errors', '0'); |
45
|
|
|
ini_set('display_errors', '0'); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Prepare some PHP config |
51
|
|
|
*/ |
52
|
|
|
public static function set(array $config = []): void |
53
|
|
|
{ |
54
|
|
|
date_default_timezone_set($config['timezone'] ?? 'America/Montreal'); |
55
|
|
|
|
56
|
|
|
setlocale(LC_ALL, 'fr_CA.' . $config['encoding'], 'French_Canada.1252'); |
57
|
|
|
mb_internal_encoding($config['encoding'] ?? 'UTF-8'); |
58
|
|
|
mb_http_output($config['encoding'] ?? 'UTF-8'); |
59
|
|
|
|
60
|
|
|
ini_set('memory_limit', $config['memoryLimit'] ?? '256M'); |
61
|
|
|
ini_set('max_execution_time', $config['timeoutLimit'] ?? '60'); |
62
|
|
|
set_time_limit($config['timeoutLimit'] ?? 60); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|