forked from kytvi2p/ZettaFramework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBootstrap.php
112 lines (89 loc) · 3 KB
/
Bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
require_once 'BootstrapQuick.php';
class Bootstrap extends BootstrapQuick
{
protected function _initEncoding()
{
parent::_initEncoding();
}
protected function _initOptParams()
{
parent::_initOptParams();
}
protected function _initLoader()
{
parent::_initLoader();
}
protected function _initConfigRegistry()
{
parent::_initConfigRegistry();
}
protected function _initSiteConfig()
{
$this->bootstrap('View');
$bootsrapSettings = new Modules_Settings_Bootstrap();
$bootsrapSettings->bootstrap();
}
protected function _initRegisterLogger()
{
parent::_initRegisterLogger();
}
/**
* Загружаем Bootstrap модулей
*/
protected function _initModules()
{
$this->bootstrap('Frontcontroller');
$this->bootstrap('Db');
$this->bootstrap('Session');
$priorityFile = realpath(HEAP_PATH . DS . 'Modules.php');
$arrayPriority = $priorityFile ? require_once $priorityFile : array();
$bootstraps = glob(MODULES_PATH . DS . '*' . DS . 'Bootstrap.php');
$bootstraps = array_merge($bootstraps, $arrayPriority, glob(HEAP_PATH . DS . '*' . DS . 'Bootstrap.php'));
$modules = array();
foreach ($bootstraps as $path) {
$moduleName = $this->_moduleName($path);
if (!isset($modules[$moduleName])) {
$moduleLoaded = $this->_loadModuleFromPath($path);
if ($moduleLoaded) {
$modules[$moduleName] = $moduleLoaded;
}
}
}
Zend_Registry::set('modules', $modules);
}
/**
* Загружаем модуль по определенному пути
* @param string $path
* @return string | false Путь к загруженному модулю или false
*/
protected function _loadModuleFromPath($path)
{
Zend_Loader::loadFile($path, null, 1);
$moduleName = $this->_moduleName($path);
$bootstrapClass = $moduleName . '_Bootstrap';
if (class_exists($bootstrapClass, false)) {
$moduleBootstrap = new $bootstrapClass();
$moduleBootstrap->bootstrap();
return dirname($path);
}
$bootstrapClassNS = str_replace('_', '\\', $bootstrapClass);
if (class_exists($bootstrapClassNS, false)) {
$moduleBootstrap = new $bootstrapClassNS();
$moduleBootstrap->bootstrap();
return dirname($path);
}
return false;
}
/**
* Делаем имя модуля из пути к нему
* @param string $path
* @return string
*/
protected function _moduleName($path)
{
$temp = explode(DS, $path);
$prefix = $temp[sizeof($temp) - 3] == 'Modules' ? 'Modules_' : '';
return $prefix . $temp[sizeof($temp) - 2];
}
}