Passed
Push — develop ( 3f93f2...48e2a7 )
by Jens
02:49
created

CloudControl::setLocalisation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by jensk on 14-8-2017.
4
 */
5
6
namespace CloudControl\Cms;
7
8
use CloudControl\Cms\cc\Application;
9
use CloudControl\Cms\storage\Cache;
10
use CloudControl\Cms\storage\Repository;
11
use Composer\Script\Event;
12
13
class CloudControl
14
{
15
    /**
16
     * @param $dir
17
     * @return \stdClass
18
     */
19
    public static function prepare($dir)
20
    {
21
        self::iniSets();
22
        self::setInternalEncoding();
23
        self::setLocalisation();
24
25
26
        ob_start('sanitize_output');
27
        session_start();
28
29
        $rootDir = realpath($dir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
30
        $configPath = realpath($rootDir . DIRECTORY_SEPARATOR . 'config.json');
31
        $preparation = new \stdClass();
32
        $preparation->rootDir = $rootDir;
33
        $preparation->configPath = $configPath;
34
        return $preparation;
35
    }
36
37
    /**
38
     * @param string $rootDir
39
     * @param string $configPath
40
     * @throws \Exception
41
     */
42
    public static function run($rootDir, $configPath)
43
    {
44
        new Application($rootDir, $configPath);
45
    }
46
47
    public static function cliServerServeResource($dir)
48
    {
49
        if (PHP_SAPI === 'cli-server') {
50
            if (preg_match('/\.(?:js|ico|txt|gif|jpg|jpeg|png|bmp|css|html|htm|php|pdf|exe|eot|svg|ttf|woff|ogg|mp3|xml|map|scss)$/', $_SERVER['REQUEST_URI'])) {
51
                if (file_exists($dir . $_SERVER["REQUEST_URI"])) {
52
                    return true;    // serve the requested resource as-is.
53
                }
54
            }
55
        }
56
        return false;
57
    }
58
59
    /**
60
     * ini settings
61
     */
62
    private static function iniSets()
63
    {
64
        // Error settings
65
        ini_set('display_errors', true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $newvalue of ini_set(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
        ini_set('display_errors', /** @scrutinizer ignore-type */ true);
Loading history...
66
        ini_set('error_reporting', E_ALL);
67
68
        // Allow Short Open Tags
69
        ini_set('short_open_tag', true);
70
    }
71
72
    /**
73
     * Set internal encoding
74
     */
75
    private static function setInternalEncoding()
76
    {
77
        if (function_exists('mb_internal_encoding')) {
78
            mb_internal_encoding('UTF-8');
79
        }
80
    }
81
82
    /**
83
     * Time settings
84
     */
85
    private static function setLocalisation()
86
    {
87
        setlocale(LC_ALL, 'nl_NL');
88
        date_default_timezone_set('Europe/Amsterdam');
89
    }
90
91
}