Test Failed
Push — master ( 08567e...3050cc )
by Julien
08:07 queued 03:55
created

Php::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 11
ccs 0
cts 8
cp 0
crap 2
rs 10
c 0
b 0
f 0
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