1: <?php
2:
3: defined('_JOOS_CORE') or exit();
4:
5: /**
6: * Автоматический сборщик классов системы и их расположения
7: *
8: * @version 1.0
9: * @package Core\Libraries
10: * @subpackage RobotLoader
11: * @category Libraries
12: * @author Joostina Team <info@joostina.ru>
13: * @copyright (C) 2007-2012 Joostina Team
14: * @license MIT License http://www.opensource.org/licenses/mit-license.php
15: * Информация об авторах и лицензиях стороннего кода в составе Joostina CMS: docs/copyrights
16: *
17: * Оригинальная идея базируется на разработках Nette FW https://github.com/nette/nette/blob/master/Nette/Loaders/RobotLoader.php
18: * */
19: class joosRobotLoader
20: {
21: public static function get_classes($location)
22: {
23: $directory = new RecursiveDirectoryIterator($location);
24: $iterator = new RecursiveIteratorIterator($directory);
25: $regex = new RegexIterator($iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);
26:
27: $classes = array();
28: foreach ($regex as $path) {
29:
30: $expected = FALSE;
31: $level = $minLevel = 0;
32:
33: $name = '';
34:
35: $file = $path[0];
36:
37: if (!joosFile::is_readable($file)) {
38: continue;
39: }
40:
41: $php_file_source = file_get_contents($file);
42:
43: $class_location = str_replace(JPATH_BASE . DS, '', $file);
44:
45: foreach (@token_get_all($php_file_source) as $token) {
46: if (is_array($token)) {
47: switch ($token[0]) {
48: case T_COMMENT:
49: case T_DOC_COMMENT:
50: case T_WHITESPACE:
51: continue 2;
52:
53: case T_NS_SEPARATOR:
54: case T_STRING:
55: if ($expected) {
56: $name .= $token[1];
57: }
58: continue 2;
59:
60: case T_CLASS:
61: case T_INTERFACE:
62: $expected = $token[0];
63: $name = '';
64: continue 2;
65: case T_CURLY_OPEN:
66: case T_DOLLAR_OPEN_CURLY_BRACES:
67: $level++;
68: }
69: }
70:
71: if ($expected) {
72: switch ($expected) {
73: case T_CLASS:
74: case T_INTERFACE:
75: if ($level === $minLevel) {
76: $classes[$name] = $class_location;
77: }
78: break;
79: }
80:
81: $expected = NULL;
82: }
83:
84: if ($token === '{') {
85: $level++;
86: } elseif ($token === '}') {
87: $level--;
88: }
89: }
90: }
91:
92: ksort($classes);
93:
94: return $classes;
95: }
96:
97: }
98: