1 | <?php |
---|
2 | |
---|
3 | if ( ! isset( $spl_autoloaders ) ) { |
---|
4 | $spl_autoloaders = array(); |
---|
5 | } |
---|
6 | |
---|
7 | /** |
---|
8 | * Autoloader compatibility callback. |
---|
9 | * |
---|
10 | * @param string $classname Class to attempt autoloading. |
---|
11 | */ |
---|
12 | function __autoload( $classname ) { |
---|
13 | global $spl_autoloaders; |
---|
14 | foreach ( $spl_autoloaders as $autoloader ) { |
---|
15 | call_user_func( $autoloader, $classname ); |
---|
16 | |
---|
17 | // If it has been autoloaded, stop processing. |
---|
18 | if ( class_exists( $classname, false ) ) { |
---|
19 | return; |
---|
20 | } |
---|
21 | } |
---|
22 | } |
---|
23 | |
---|
24 | /** |
---|
25 | * Register a function to be autoloaded. |
---|
26 | * |
---|
27 | * @param callable $autoload_function The function to register. |
---|
28 | * @param boolean $throw Should the function throw an exception if the function isn't callable? |
---|
29 | * @param boolean $prepend Should we prepend the function to the stack? |
---|
30 | */ |
---|
31 | function spl_autoload_register( $autoload_function, $throw = true, $prepend = false ) { |
---|
32 | if ( $throw && ! is_callable( $autoload_function ) ) { |
---|
33 | // String not translated to match PHP core. |
---|
34 | throw new Exception( 'Function not callable' ); |
---|
35 | } |
---|
36 | |
---|
37 | global $spl_autoloaders; |
---|
38 | |
---|
39 | // Don't allow multiple registration. |
---|
40 | if ( in_array( $autoload_function, $spl_autoloaders ) ) { |
---|
41 | return; |
---|
42 | } |
---|
43 | |
---|
44 | if ( $prepend ) { |
---|
45 | array_unshift( $spl_autoloaders, $autoload_function ); |
---|
46 | } else { |
---|
47 | $spl_autoloaders[] = $autoload_function; |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * Unregister an autoloader function. |
---|
53 | * |
---|
54 | * @param callable $function The function to unregister. |
---|
55 | * @return boolean True if the function was unregistered, false if it could not be. |
---|
56 | */ |
---|
57 | function spl_autoload_unregister( $function ) { |
---|
58 | global $spl_autoloaders; |
---|
59 | foreach ( $spl_autoloaders as &$autoloader ) { |
---|
60 | if ( $autoloader === $function ) { |
---|
61 | unset( $autoloader ); |
---|
62 | return true; |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | return false; |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * Get the registered autoloader functions. |
---|
71 | * |
---|
72 | * @return array List of autoloader functions. |
---|
73 | */ |
---|
74 | function spl_autoload_functions() { |
---|
75 | return $GLOBALS['spl_autoloaders']; |
---|
76 | } |
---|