-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.php
More file actions
executable file
·155 lines (129 loc) · 4.09 KB
/
loader.php
File metadata and controls
executable file
·155 lines (129 loc) · 4.09 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* Загрузчик основных библиотек
*
* @project SamCMS
* @author Kash
* @package root
* @date 28.07.12
* @copyright Copyright (c) 2013, Kash <deadkash@gmail.com>
*/
class Autoloader {
/** @var string Путь приложения */
private static $appPath = null;
/**
* Классы ядра
* @var array
*/
private static $coreClasses = array(
'Application',
'Access',
'DB',
'Debug',
'Hash',
'Log',
'Mailer',
'Parameters',
'Request',
'Router',
'Templater',
'Translate',
'Messages',
'Seo',
'Language',
'Fields',
'Captcha',
'Image',
'header',
'Cache',
'Installation'
);
/**
* Классы классов
* @var array
*/
private static $classClasses = array(
'Component',
'Controller',
'Core',
'Editor',
'Model',
'Module',
'Route',
'View',
'Document',
'Plugin',
'Field',
'Install'
);
/**
* Установка пути к приложению
* @param string $path
*/
public static function setAppPath($path){
self::$appPath = $path;
}
/**
* Метод вызывается при попытке создания экземпляра класса, которого нет в окружении приложения
* @param $className string
*/
public static function load($className) {
if (empty(self::$appPath)) self::$appPath = APP_PATH;
$className = preg_replace('/([a-z])([A-Z])/', '$1_$2', $className);
$pathArray = explode('_', $className);
$name = false;
$type = false;
$path = false;
if (isset($pathArray[0])) $name = $pathArray[0];
if (isset($pathArray[1])) $type = $pathArray[1];
//Если класс ядра
if (in_array($className, self::$coreClasses)) {
$type = 'Core';
$name = $className;
}
//Если класс классов
if (in_array($className, self::$classClasses)) {
$type = 'Class';
$name = $className;
}
switch ($type) {
case 'Core':
$path = __DIR__.'/core/'.$name.'.php';
break;
case 'Class':
$path = __DIR__.'/core/classes/'.$name.'.php';
break;
case 'Helper':
$path = __DIR__.'/core/helpers/'.$name.'.php';
break;
case 'Controller':
$controller = $pathArray[2];
$path = self::$appPath.'components/'.strtolower($name).'/controllers/'.$controller.'.php';
break;
case 'View':
$view = $pathArray[2];
$path = self::$appPath.'components/'.strtolower($name).'/views/'.strtolower($view).'/'.$view.'.php';
break;
case 'Model':
$model = $pathArray[2];
$path = self::$appPath.'components/'.strtolower($name).'/models/'.$model.'.php';
break;
case 'Consts':
$path = self::$appPath.'components/'.strtolower($name).'/Consts.php';
}
if ($path && file_exists($path)) require_once($path);
}
}
//Определение путей
$rootPath = __DIR__.'/';
if (defined('ADMIN')) $rootPath .= 'admin/';
define('APP_PATH', $rootPath);
define('ABS_PATH', __DIR__.'/');
define('PLUGINS_PATH', APP_PATH.'plugins/');
//E-mail для ответов
define('NOREPLY_EMAIL', 'no-reply@'.str_replace('www.','', $_SERVER['HTTP_HOST']));
$startTime = microtime(1);
if (file_exists(ABS_PATH.'config.php')) require_once('config.php');
require_once('lib/Twig/Autoloader.php');
Twig_Autoloader::register();
spl_autoload_register(array('Autoloader', 'load'));