My favorites
▼
|
Sign in
yadro
yadro on ZF
Project Home
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
system
/
modules
/
core
/
models
/
Loader.php
‹r2
r11
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?php
/**
* Core_Loader
*
* @author naspeh
* @version $Id: Loader.php 668 2008-06-30 10:01:20Z naspeh $
*/
require_once 'Zend/Loader.php';
class Core_Loader
{
/**
* Директория конфигураций
*
*/
const SUFFIX_CONFIGS = 'configs';
/**
* Директория контроллеров
*
*/
const SUFFIX_CONTROLLERS = 'controllers';
/**
* Директория моделей
*
*/
const SUFFIX_MODELS = 'models';
/**
* Директория представлений
*
*/
const SUFFIX_VIEWS = 'views';
/**
* Модуль по умолчанию
*
*/
const MODULE_DEFAULT = 'core';
/**
* Стек: префикс - путь
*
* @var array
*/
protected static $_prefixToPaths = null;
/**
* Стек: модуль - путь
*
* @var array
*/
protected static $_moduleToPaths = array();
/**
* Директория модулей
*
* @var string
*/
protected static $_moduleDir;
/**
* Добавляет пару: префикс - путь
*
* @param string $path
* @param string $prefix
*/
public static function addPrefixToPath($path, $prefix)
{
$path = (string) $path;
$prefix = rtrim($prefix, '_') . '_';
if (is_dir($path)) {
self::$_prefixToPaths[$prefix][] = rtrim($path, '/\\') . DIRECTORY_SEPARATOR;
} else {
throw new Core_Exception('pathNotDir# ' . $path);
}
}
/**
* Добавляет директорию
*
* @param string $path
* @param string $suffixToModels
*/
public static function addDir($path, $suffixToModels = null)
{
try {
$dir = new DirectoryIterator($path);
} catch(Exception $e) {
require_once 'Exception.php';
throw new Core_Exception('dirNotReadable# Директория: "' . $path . '" не читаемая');
}
foreach ($dir as $file) {
if ($file->isDot() || !$file->isDir()) {
continue;
}
$prefix = $file->getFilename();
require_once 'Zend/Filter.php';
require_once 'Zend/Filter/Word/DashToCamelCase.php';
$chain = new Zend_Filter();
$chain->addFilter(new Zend_Filter_Word_DashToCamelCase());
$prefix = $chain->filter($prefix);
// Don't use SCCS directories as modules
if (preg_match('/^[^a-z]/i', $prefix) || ('CVS' == $prefix)) {
continue;
}
$modelsDir = $file->getPathname();
if (isset($suffixToModels)) {
$modelsDir .= DIRECTORY_SEPARATOR . $suffixToModels;
}
if (is_dir($modelsDir)) {
self::addPrefixToPath($modelsDir, $prefix);
}
}
}
/**
* Ищет файл с классом, если находит, то подключает его(include_once)
*
* @param string $class
*/
public static function loadClass($class)
{
$class = (string) $class;
if (class_exists($class)) {
return;
}
$paths = self::getPrefixToPath();
foreach ($paths as $prefix => $paths) {
if (preg_match('/^' . $prefix . '(\w+)/', $class, $matches)) {
$fileEnd = $matches[1];
$fileEnd = str_replace('_', '/', $fileEnd) . '.php';
foreach ($paths as $path) {
$file = $path . $fileEnd;
if (Zend_Loader::isReadable($file)) {
include_once $file;
if (! class_exists($class, false) && ! interface_exists($class, false)) {
require_once 'Exception.php';
throw new Core_Exception('classNotExists');
}
return;
}
}
}
}
require_once 'Exception.php';
throw new Core_Exception('fileNotLoad');
}
/**
* Возвращает стек или элемент стека
*
* @param string $prefix
* @return array|string|false
*/
public static function getPrefixToPath($prefix = '')
{
$prefix = (string) $prefix;
if (empty($prefix)) {
return self::$_prefixToPaths;
} elseif (isset(self::$_prefixToPaths[$prefix])) {
return self::$_prefixToPaths[$prefix];
} else {
return false;
}
}
/**
* Регистрирует автолоадер
*
* @param boolean $enabled
*/
public static function registerAutoload($enabled = true)
{
Zend_Loader::registerAutoload(get_class(new self()), $enabled);
}
/**
* spl_autoload() suitable implementation for supporting class autoloading.
*
* @param string $class
* @return string|false Class name on success; false on failure
*/
public static function autoload($class)
{
try {
self::loadClass($class);
return $class;
} catch (Exception $e) {
return false;
}
}
/**
* Удаляет пару префикс - путь
*
* @param string $prefix
* @return boolean
*/
public static function removePrefixToPath($prefix = '')
{
$prefix = (string) $prefix;
if (empty($prefix)) {
self::$_prefixToPaths = null;
} elseif (isset(self::$_prefixToPaths[$prefix])) {
unset(self::$_prefixToPaths[$prefix]);
} else {
return false;
}
return true;
}
/**
* Добаляет связку "имя модуля" => "путь к паке с модулем"
*
* @param string $module
* @param string $path
* @return Core_Module
*/
public static function addModuleToPath ($path, $module)
{
$module = (string) $module;
$path = (string) $path;
if (is_dir($path)) {
self::$_moduleToPaths[$module] = rtrim($path, '/\\') . DIRECTORY_SEPARATOR;
} else {
require_once 'Exception.php';
throw new Core_Exception('pathNotDir# ' . $path);
}
}
/**
* Устанавливает директорию с модулями.
*
* @param string $path
* @return string
*/
public static function setModuleDir ($path)
{
try{
$dir = new DirectoryIterator($path);
}catch(Exception $e){
require_once 'Exception.php';
throw new Core_Exception('dirNotReadable# Директория: "' . $path . '" не читаемая');
}
self::clearModuleDir();
self::$_moduleDir = $dir->getPath() . DIRECTORY_SEPARATOR;
foreach ($dir as $file) {
if ($file->isDot() || !$file->isDir()) {
continue;
}
$module = $file->getFilename();
// Don't use SCCS directories as modules
if (preg_match('/^[^a-z]/i', $module) || ('CVS' == $module)) {
continue;
}
$moduleDir = $file->getPathname();
self::addModuleToPath($moduleDir, $module);
}
return self::$_moduleDir;
}
/**
* Возвращает установленную директорию с модулями.
*
* @return string
*/
public static function getModuleDir ()
{
return self::$_moduleDir;
}
/**
* Очищает установленную директорию с модулями.
*
* @return true
*/
public static function clearModuleDir ()
{
self::$_moduleDir = null;
self::$_moduleToPaths = array();
return true;
}
/**
* Возвращает связку "имя модуля" => "путь к паке с модулем", все если $module = ''
*
* @param string $module
* @return mixed
*/
public static function getModuleToPath ($module = '')
{
$module = (string) $module;
if (empty($module)) {
return self::$_moduleToPaths;
} elseif (isset(self::$_moduleToPaths[$module])) {
return self::$_moduleToPaths[$module];
} else {
return false;
}
}
}
Show details
Hide details
Change log
r3
by naspeh on Jul 5, 2008
Diff
rename aothor
Go to:
/trunk/.project
/trunk/system/boot/setup.php
/trunk/system/boot/tests.php
/trunk/system/boot/web.php
...tem/modules/core/configs/bar.php
...les/core/configs/cache.local.php
...m/modules/core/configs/cache.php
...es/core/configs/common.local.php
.../modules/core/configs/common.php
.../core/configs/database.local.php
...odules/core/configs/database.php
...s/core/configs/database.test.php
...dules/core/configs/informant.php
...odules/core/configs/messages.php
.../modules/core/configs/routes.php
...ontrollers/ContentController.php
.../controllers/ErrorController.php
.../controllers/IndexController.php
...ers/Personal/EmailChangeForm.php
...ntrollers/Personal/LoginForm.php
.../Personal/PasswordChangeForm.php
...rollers/Personal/ProfileForm.php
...trollers/Personal/SignupForm.php
...ntrollers/PersonalController.php
.../controllers/Role/AccessForm.php
...ore/controllers/Role/AddForm.php
...re/controllers/Role/EditForm.php
...core/controllers/Role/Record.php
...e/controllers/RoleController.php
...controllers/SystemController.php
...stem/modules/core/models/Acl.php
...models/Acl/Controller/Plugin.php
...models/Acl/Resource/Abstract.php
...e/models/Acl/Resource/Action.php
...ore/models/Acl/Resource/Role.php
...ore/models/Acl/Resource/Type.php
...modules/core/models/Acl/Role.php
...tem/modules/core/models/Auth.php
...em/modules/core/models/Cache.php
...m/modules/core/models/Config.php
...ore/models/Controller/Action.php
...Action/Helper/FlashMessenger.php
...core/models/Controller/Front.php
...Controller/Plugin/DbProfiler.php
.../Controller/Plugin/HeadTitle.php
...ntroller/Router/Route/Module.php
...ystem/modules/core/models/Db.php
...odules/core/models/Exception.php
...tem/modules/core/models/Form.php
...odules/core/models/Informant.php
Project members,
sign in
to write a code review
Older revisions
r2
by naspeh on Jul 5, 2008
Diff
start in web
All revisions of this file
File info
Size: 8868 bytes, 283 lines
View raw file
Powered by
Google Project Hosting