1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* @author PhileCMS |
4
|
|
|
* @link https://philecms.com |
5
|
|
|
* @license http://opensource.org/licenses/MIT |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Phile\Core; |
9
|
|
|
|
10
|
|
|
use Phile\Core\Config; |
11
|
|
|
use Phile\Core\Event; |
12
|
|
|
use Phile\Core\ServiceLocator; |
13
|
|
|
use Phile\Exception\PluginException; |
14
|
|
|
use Phile\Plugin\PluginRepository; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Bootstrap class |
18
|
|
|
*/ |
19
|
|
|
class Bootstrap |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Loads $file into $configuration |
23
|
|
|
*/ |
24
|
|
|
public static function loadConfiguration($file, Config $config) |
25
|
|
|
{ |
26
|
|
|
// function isolates context of loaded files |
27
|
29 |
|
$load = function ($file) { |
28
|
29 |
|
return include $file; |
29
|
29 |
|
}; |
30
|
29 |
|
$config->merge($load($file)); |
31
|
29 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Creates and protects folder and path $directory |
35
|
|
|
*/ |
36
|
1 |
|
public static function setupFolder($directory, Config $config) |
37
|
|
|
{ |
38
|
1 |
|
if (empty($directory) || strpos($directory, $config->get('root_dir')) !== 0) { |
39
|
|
|
return; |
40
|
|
|
} |
41
|
1 |
|
if (!file_exists($directory)) { |
42
|
1 |
|
mkdir($directory, 0775, true); |
43
|
|
|
} |
44
|
1 |
|
$htaccessPath = "$directory.htaccess"; |
45
|
1 |
|
if (!file_exists($htaccessPath)) { |
46
|
1 |
|
$htaccessContent = "order deny,allow\ndeny from all\nallow from 127.0.0.1"; |
47
|
1 |
|
file_put_contents($htaccessPath, $htaccessContent); |
48
|
|
|
} |
49
|
1 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Initializes error handling |
53
|
|
|
*/ |
54
|
1 |
|
public static function setupErrorHandler(Config $config) |
55
|
|
|
{ |
56
|
1 |
|
$cliMode = $config->get('phile_cli_mode'); |
57
|
1 |
|
if ($cliMode || !ServiceLocator::hasService('Phile_ErrorHandler')) { |
58
|
|
|
return; |
59
|
|
|
} |
60
|
1 |
|
$errorHandler = ServiceLocator::getService('Phile_ErrorHandler'); |
61
|
1 |
|
set_error_handler([$errorHandler, 'handleError']); |
62
|
1 |
|
set_exception_handler([$errorHandler, 'handleException']); |
63
|
1 |
|
register_shutdown_function([$errorHandler, 'handleShutdown']); |
64
|
1 |
|
} |
65
|
|
|
} |
66
|
|
|
|