| | 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 | if ( ! is_callable( $autoloader ) ) { |
| | 451 | // Avoid the extra warning if the autoloader isn't callable. |
| | 452 | continue; |
| | 453 | } |
| | 454 | |
| | 455 | call_user_func( $autoloader, $classname ); |
| | 456 | |
| | 457 | // If it has been autoloaded, stop processing. |
| | 458 | if ( class_exists( $classname, false ) ) { |
| | 459 | return; |
| | 460 | } |
| | 461 | } |
| | 462 | } |
| | 463 | |
| | 464 | /** |
| | 465 | * Register a function to be autoloaded. |
| | 466 | * |
| | 467 | * @param callable $autoload_function The function to register. |
| | 468 | * @param boolean $throw Should the function throw an exception if the function isn't callable? |
| | 469 | * @param boolean $prepend Should we prepend the function to the stack? |
| | 470 | */ |
| | 471 | function spl_autoload_register( $autoload_function, $throw = true, $prepend = false ) { |
| | 472 | if ( $throw && ! is_callable( $autoload_function ) ) { |
| | 473 | // String not translated to match PHP core. |
| | 474 | throw new Exception( 'Function not callable' ); |
| | 475 | } |
| | 476 | |
| | 477 | global $_wp_spl_autoloaders; |
| | 478 | |
| | 479 | // Don't allow multiple registration. |
| | 480 | if ( in_array( $autoload_function, $_wp_spl_autoloaders ) ) { |
| | 481 | return; |
| | 482 | } |
| | 483 | |
| | 484 | if ( $prepend ) { |
| | 485 | array_unshift( $_wp_spl_autoloaders, $autoload_function ); |
| | 486 | } else { |
| | 487 | $_wp_spl_autoloaders[] = $autoload_function; |
| | 488 | } |
| | 489 | } |
| | 490 | |
| | 491 | /** |
| | 492 | * Unregister an autoloader function. |
| | 493 | * |
| | 494 | * @param callable $function The function to unregister. |
| | 495 | * @return boolean True if the function was unregistered, false if it could not be. |
| | 496 | */ |
| | 497 | function spl_autoload_unregister( $function ) { |
| | 498 | global $_wp_spl_autoloaders; |
| | 499 | foreach ( $_wp_spl_autoloaders as &$autoloader ) { |
| | 500 | if ( $autoloader === $function ) { |
| | 501 | unset( $autoloader ); |
| | 502 | return true; |
| | 503 | } |
| | 504 | } |
| | 505 | |
| | 506 | return false; |
| | 507 | } |
| | 508 | |
| | 509 | /** |
| | 510 | * Get the registered autoloader functions. |
| | 511 | * |
| | 512 | * @return array List of autoloader functions. |
| | 513 | */ |
| | 514 | function spl_autoload_functions() { |
| | 515 | return $GLOBALS['_wp_spl_autoloaders']; |
| | 516 | } |
| | 517 | endif; |