-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathoo-spl-autoload.php
56 lines (53 loc) · 1.41 KB
/
oo-spl-autoload.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
<?php
use PhpParser\Node;
trait OOEmulator_spl_autoload
{
protected $autoloaders=[];
public function spl_autoload_register($callback=null, $throw=true, $prepend=false)
{
if ($callback===null)
$callback="spl_autoload"; //default autoloader of php
if ($prepend)
array_unshift($this->autoloaders, $callback);
else
$this->autoloaders[]=$callback;
return true;
}
public function spl_autoload_unregister($callback)
{
if ( ($key=array_search($callback, $this->autoloaders))!==false)
{
unset($this->autoloaders[$key]);
return true;
}
return false;
}
public function spl_autoload_functions()
{
return $this->autoloaders;
}
public function spl_autoload_call($class)
{
if (empty($this->autoloaders)) return;
$this->verbose("Attempting to autoload '{$class}'...\n",3);
foreach ($this->autoloaders as $autoloader)
if ($this->class_exists($class)) break;
else
{
$this->verbose("Calling the next autoloader to autoload '{$class}'...\n",4);
$this->call_function($autoloader,[$class]);
}
$this->verbose("Autoloading '{$class}' completed.\n",3);
}
protected $autoload_extensions=".inc,.php";
public function spl_autoload_extensions($extensions=null)
{
if ($extensions===null) return $this->autoload_extensions;
spl_autoload_extensions($extensions);
$this->autoload_extensions=$extensions;
}
function autoload($class)
{
return $this->spl_autoload_call($class);
}
}