| | 437 | |
| | 438 | // SPL can be disabled on PHP 5.2 |
| | 439 | if ( ! function_exists( 'spl_autoload_register' ) ): |
| | 440 | $_wp_spl_autoloaders = array(); |
| | 441 | |
| | 442 | /** |
| | 443 | * Autoloader compatibility callback. |
| | 444 | * |
| | 445 | * @param string $classname Class to attempt autoloading. |
| | 446 | */ |
| | 447 | function __autoload( $classname ) { |
| | 448 | global $_wp_spl_autoloaders; |
| | 449 | foreach ( $_wp_spl_autoloaders as $autoloader ) { |
| | 450 | call_user_func( $autoloader, $classname ); |
| | 451 | |
| | 452 | // If it has been autoloaded, stop processing. |
| | 453 | if ( class_exists( $classname, false ) ) { |
| | 454 | return; |
| | 455 | } |
| | 456 | } |
| | 457 | } |
| | 458 | |
| | 459 | /** |
| | 460 | * Register a function to be autoloaded. |
| | 461 | * |
| | 462 | * @param callable $autoload_function The function to register. |
| | 463 | * @param boolean $throw Should the function throw an exception if the function isn't callable? |
| | 464 | * @param boolean $prepend Should we prepend the function to the stack? |
| | 465 | */ |
| | 466 | function spl_autoload_register( $autoload_function, $throw = true, $prepend = false ) { |
| | 467 | if ( $throw && ! is_callable( $autoload_function ) ) { |
| | 468 | // String not translated to match PHP core. |
| | 469 | throw new Exception( 'Function not callable' ); |
| | 470 | } |
| | 471 | |
| | 472 | global $_wp_spl_autoloaders; |
| | 473 | |
| | 474 | // Don't allow multiple registration. |
| | 475 | if ( in_array( $autoload_function, $_wp_spl_autoloaders ) ) { |
| | 476 | return; |
| | 477 | } |
| | 478 | |
| | 479 | if ( $prepend ) { |
| | 480 | array_unshift( $_wp_spl_autoloaders, $autoload_function ); |
| | 481 | } else { |
| | 482 | $_wp_spl_autoloaders[] = $autoload_function; |
| | 483 | } |
| | 484 | } |
| | 485 | |
| | 486 | /** |
| | 487 | * Unregister an autoloader function. |
| | 488 | * |
| | 489 | * @param callable $function The function to unregister. |
| | 490 | * @return boolean True if the function was unregistered, false if it could not be. |
| | 491 | */ |
| | 492 | function spl_autoload_unregister( $function ) { |
| | 493 | global $_wp_spl_autoloaders; |
| | 494 | foreach ( $_wp_spl_autoloaders as &$autoloader ) { |
| | 495 | if ( $autoloader === $function ) { |
| | 496 | unset( $autoloader ); |
| | 497 | return true; |
| | 498 | } |
| | 499 | } |
| | 500 | |
| | 501 | return false; |
| | 502 | } |
| | 503 | |
| | 504 | /** |
| | 505 | * Get the registered autoloader functions. |
| | 506 | * |
| | 507 | * @return array List of autoloader functions. |
| | 508 | */ |
| | 509 | function spl_autoload_functions() { |
| | 510 | return $GLOBALS['_wp_spl_autoloaders']; |
| | 511 | } |
| | 512 | endif; |