|
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
|
|
|
} |