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\Bootstrap; |
13
|
|
|
|
14
|
|
|
use Zemit\Di\Injectable; |
15
|
|
|
|
16
|
|
|
class Prepare extends Injectable |
17
|
|
|
{ |
18
|
|
|
public function __construct() |
19
|
|
|
{ |
20
|
|
|
$this->initialize(); |
21
|
|
|
$this->trustForwardedProto(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Initialisation |
26
|
|
|
*/ |
27
|
|
|
public function initialize(): void |
28
|
|
|
{ |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Trust forwarded protocol and force $_SERVER['https'] to 'on' |
33
|
|
|
* @todo move this to request? |
34
|
|
|
*/ |
35
|
|
|
public function trustForwardedProto(): void |
36
|
|
|
{ |
37
|
|
|
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '', 'https') !== false) { |
38
|
|
|
$_SERVER['HTTPS'] = 'on'; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Prepare debugging |
44
|
|
|
* @todo review this |
45
|
|
|
*/ |
46
|
|
|
public function debug(?bool $debug = null): void |
47
|
|
|
{ |
48
|
|
|
$debug ??= $this->config->get('app.debug') || $this->config->get('debug.enable'); |
49
|
|
|
if ($debug) { |
50
|
|
|
// Enabling error reporting and display |
51
|
|
|
error_reporting(E_ALL); |
52
|
|
|
ini_set('display_errors', 1); |
53
|
|
|
} else { |
54
|
|
|
// Disabling error reporting and display |
55
|
|
|
error_reporting(-1); |
56
|
|
|
ini_set('display_errors', 0); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Prepare some PHP config |
62
|
|
|
* @todo review this |
63
|
|
|
*/ |
64
|
|
|
public function php(array $config = []): void |
65
|
|
|
{ |
66
|
|
|
date_default_timezone_set($config['timezone'] ?? 'America/Montreal'); |
67
|
|
|
|
68
|
|
|
setlocale(LC_ALL, 'fr_CA.' . $config['encoding'], 'French_Canada.1252'); |
69
|
|
|
mb_internal_encoding($config['encoding'] ?? 'UTF-8'); |
70
|
|
|
mb_http_output($config['encoding'] ?? 'UTF-8'); |
71
|
|
|
|
72
|
|
|
ini_set('memory_limit', $config['memoryLimit'] ?? '256M'); |
73
|
|
|
ini_set('max_execution_time', $config['timeoutLimit'] ?? '60'); |
74
|
|
|
set_time_limit($config['timeoutLimit'] ?? 60); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|