Nextrek
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
|
<?php
namespace ClassPreloader;
require_once __DIR__ . '/ClassNode.php';
require_once __DIR__ . '/ClassList.php';
/**
* Creates an autoloader that intercepts and keeps track of each include in
* order that files must be included. This autoloader proxies to all other
* underlying autoloaders.
*/
class ClassLoader
{
/**
* @var ClassList List of loaded classes
*/
public $classList;
/**
* Create the dependency list
*/
public function __construct()
{
$this->classList = new ClassList();
}
/**
* Wrap a block of code in the autoloader and get a list of loaded classes
*
* @param \Callable $func Callable function
*
* @return Config
*/
public static function getIncludes($func)
{
$loader = new self();
call_user_func($func, $loader);
$loader->unregister();
$config = new Config();
foreach ($loader->getFilenames() as $file) {
$config->addFile($file);
}
return $config;
}
/**
* Registers this instance as an autoloader.
*/
public function register()
{
spl_autoload_register(array($this, 'loadClass'), true, true);
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True, if loaded
*/
public function loadClass($class)
{
foreach (spl_autoload_functions() as $func) {
if (is_array($func) && $func[0] === $this) {
continue;
}
$this->classList->push($class);
if (call_user_func($func, $class)) {
break;
}
}
$this->classList->next();
return true;
}
/**
* Get an array of loaded file names in order of loading
*
* @return array
*/
public function getFilenames()
{
$files = array();
foreach ($this->classList->getClasses() as $class) {
// Push interfaces before classes if not already loaded
$r = new \ReflectionClass($class);
foreach ($r->getInterfaces() as $inf) {
$name = $inf->getFileName();
if ($name && !in_array($name, $files)) {
$files[] = $name;
}
}
$files[] = $r->getFileName();
}
return $files;
}
}
|
Revision |
Author |
Commited |
Message |
1464
|
MOliva
|
Tue 13 Oct, 2020 11:16:56 +0000 |
|