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\cc\ComposerScripts; |
10
|
|
|
use Composer\Script\Event; |
11
|
|
|
|
12
|
|
|
class CloudControl |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param $dir |
16
|
|
|
* @return \stdClass |
17
|
|
|
*/ |
18
|
|
|
public static function prepare($dir) |
19
|
|
|
{ |
20
|
|
|
self::iniSets(); |
21
|
|
|
self::setInternalEncoding(); |
22
|
|
|
self::setLocalisation(); |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
ob_start('\CloudControl\Cms\util\GlobalFunctions::sanitizeOutput'); |
26
|
|
|
session_start(); |
27
|
|
|
|
28
|
|
|
$rootDir = realpath($dir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR); |
29
|
|
|
$configPath = realpath($rootDir . DIRECTORY_SEPARATOR . 'config.json'); |
30
|
|
|
$preparation = new \stdClass(); |
31
|
|
|
$preparation->rootDir = $rootDir; |
32
|
|
|
$preparation->configPath = $configPath; |
33
|
|
|
return $preparation; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $rootDir |
38
|
|
|
* @param string $configPath |
39
|
|
|
* @throws \Exception |
40
|
|
|
*/ |
41
|
|
|
public static function run($rootDir, $configPath) |
42
|
|
|
{ |
43
|
|
|
new Application($rootDir, $configPath); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public static function cliServerServeResource($dir) |
47
|
|
|
{ |
48
|
|
|
if (PHP_SAPI === 'cli-server') { |
49
|
|
|
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|json)$/', |
50
|
|
|
$_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'); |
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
|
|
|
/** |
92
|
|
|
* @deprecated |
93
|
|
|
* @since v1.0.27 |
94
|
|
|
* @param Event $event |
95
|
|
|
* @throws \Exception |
96
|
|
|
*/ |
97
|
|
|
public static function postUpdate($event) |
98
|
|
|
{ |
99
|
|
|
$event->getIO()->write('[DEPRECATED] In your composer.json file, please change CloudControl\\Cms\\CloudControl::postUpdate to CloudControl\\Cms\\cc\\ComposerScripts::postUpdate'); |
100
|
|
|
ComposerScripts::checkInstall($event); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @deprecated |
105
|
|
|
* @since v1.0.27 |
106
|
|
|
* @param Event $event |
107
|
|
|
* @throws \Exception |
108
|
|
|
*/ |
109
|
|
|
public static function postInstall($event) |
110
|
|
|
{ |
111
|
|
|
$event->getIO()->write('[DEPRECATED] In your composer.json file, please change CloudControl\\Cms\\CloudControl::postInstall to CloudControl\\Cms\\cc\\ComposerScripts::postInstall'); |
112
|
|
|
ComposerScripts::checkInstall($event); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
} |