Passed
Push — master ( a1bf27...3a2d72 )
by Jens
04:20
created

CloudControl::createStorage()   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 3
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
10
class CloudControl
11
{
12
    /**
13
     * @param $dir
14
     * @return \stdClass
15
     */
16
    public static function prepare($dir)
17
    {
18
        self::iniSets();
19
        self::setInternalEncoding();
20
        self::setLocalisation();
21
22
23
        ob_start('sanitize_output');
24
        session_start();
25
26
        $rootDir = realpath($dir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
27
        $configPath = realpath($rootDir . DIRECTORY_SEPARATOR . 'config.json');
28
        $preparation = new \stdClass();
29
        $preparation->rootDir = $rootDir;
30
        $preparation->configPath = $configPath;
31
        return $preparation;
32
    }
33
34
    /**
35
     * @param string $rootDir
36
     * @param string $configPath
37
     * @throws \Exception
38
     */
39
    public static function run($rootDir, $configPath)
40
    {
41
        new Application($rootDir, $configPath);
42
    }
43
44
    public static function cliServerServeResource($dir)
45
    {
46
        if (PHP_SAPI === 'cli-server') {
47
            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)$/',
48
                $_SERVER['REQUEST_URI'])) {
49
                if (file_exists($dir . $_SERVER["REQUEST_URI"])) {
50
                    return true;    // serve the requested resource as-is.
51
                }
52
            }
53
        }
54
        return false;
55
    }
56
57
    /**
58
     * ini settings
59
     */
60
    private static function iniSets()
61
    {
62
        // Error settings
63
        ini_set('display_errors', 'true');
64
        ini_set('error_reporting', E_ALL);
65
66
        // Allow Short Open Tags
67
        ini_set('short_open_tag', 'true');
68
    }
69
70
    /**
71
     * Set internal encoding
72
     */
73
    private static function setInternalEncoding()
74
    {
75
        if (function_exists('mb_internal_encoding')) {
76
            mb_internal_encoding('UTF-8');
77
        }
78
    }
79
80
    /**
81
     * Time settings
82
     */
83
    private static function setLocalisation()
84
    {
85
        setlocale(LC_ALL, 'nl_NL');
86
        date_default_timezone_set('Europe/Amsterdam');
87
    }
88
89
}