Autoload: Introduce shim for SPL autoloading.
For PHP 5.2, SPL can be disabled. As SPL provides the support for multiple autoloaders, this needs to be shimmed if not available. Fixes #36926. git-svn-id: https://develop.svn.wordpress.org/trunk@37636 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
5259f34578
commit
e6092b8b07
@ -29,35 +29,10 @@ function wp_simplepie_autoload( $class ) {
|
|||||||
include( $file );
|
include( $file );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( function_exists( 'spl_autoload_register' ) ) {
|
/**
|
||||||
/**
|
|
||||||
* We autoload classes we may not need.
|
* We autoload classes we may not need.
|
||||||
*
|
|
||||||
* If SPL is disabled, we load all of SimplePie manually.
|
|
||||||
*
|
|
||||||
* Core.php is not loaded manually, because SimplePie_Core (a deprecated class)
|
|
||||||
* was never included in WordPress core.
|
|
||||||
*/
|
*/
|
||||||
spl_autoload_register( 'wp_simplepie_autoload' );
|
spl_autoload_register( 'wp_simplepie_autoload' );
|
||||||
} else {
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/Cache/Base.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/Cache/DB.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/Cache/File.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/Cache/Memcache.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/Cache/MySQL.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/Caption.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/Category.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/Copyright.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/Credit.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/Decode/HTML/Entities.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/Enclosure.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/gzdecode.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/HTTP/Parser.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/Net/IPv6.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/Rating.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/Restriction.php';
|
|
||||||
require ABSPATH . WPINC . '/SimplePie/Source.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SimplePie
|
* SimplePie
|
||||||
|
@ -434,3 +434,84 @@ if ( ! interface_exists( 'JsonSerializable' ) ) {
|
|||||||
if ( ! function_exists( 'random_int' ) ) {
|
if ( ! function_exists( 'random_int' ) ) {
|
||||||
require ABSPATH . WPINC . '/random_compat/random.php';
|
require ABSPATH . WPINC . '/random_compat/random.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SPL can be disabled on PHP 5.2
|
||||||
|
if ( ! function_exists( 'spl_autoload_register' ) ):
|
||||||
|
$_wp_spl_autoloaders = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Autoloader compatibility callback.
|
||||||
|
*
|
||||||
|
* @param string $classname Class to attempt autoloading.
|
||||||
|
*/
|
||||||
|
function __autoload( $classname ) {
|
||||||
|
global $_wp_spl_autoloaders;
|
||||||
|
foreach ( $_wp_spl_autoloaders as $autoloader ) {
|
||||||
|
if ( ! is_callable( $autoloader ) ) {
|
||||||
|
// Avoid the extra warning if the autoloader isn't callable.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
call_user_func( $autoloader, $classname );
|
||||||
|
|
||||||
|
// If it has been autoloaded, stop processing.
|
||||||
|
if ( class_exists( $classname, false ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a function to be autoloaded.
|
||||||
|
*
|
||||||
|
* @param callable $autoload_function The function to register.
|
||||||
|
* @param boolean $throw Should the function throw an exception if the function isn't callable?
|
||||||
|
* @param boolean $prepend Should we prepend the function to the stack?
|
||||||
|
*/
|
||||||
|
function spl_autoload_register( $autoload_function, $throw = true, $prepend = false ) {
|
||||||
|
if ( $throw && ! is_callable( $autoload_function ) ) {
|
||||||
|
// String not translated to match PHP core.
|
||||||
|
throw new Exception( 'Function not callable' );
|
||||||
|
}
|
||||||
|
|
||||||
|
global $_wp_spl_autoloaders;
|
||||||
|
|
||||||
|
// Don't allow multiple registration.
|
||||||
|
if ( in_array( $autoload_function, $_wp_spl_autoloaders ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $prepend ) {
|
||||||
|
array_unshift( $_wp_spl_autoloaders, $autoload_function );
|
||||||
|
} else {
|
||||||
|
$_wp_spl_autoloaders[] = $autoload_function;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregister an autoloader function.
|
||||||
|
*
|
||||||
|
* @param callable $function The function to unregister.
|
||||||
|
* @return boolean True if the function was unregistered, false if it could not be.
|
||||||
|
*/
|
||||||
|
function spl_autoload_unregister( $function ) {
|
||||||
|
global $_wp_spl_autoloaders;
|
||||||
|
foreach ( $_wp_spl_autoloaders as &$autoloader ) {
|
||||||
|
if ( $autoloader === $function ) {
|
||||||
|
unset( $autoloader );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the registered autoloader functions.
|
||||||
|
*
|
||||||
|
* @return array List of autoloader functions.
|
||||||
|
*/
|
||||||
|
function spl_autoload_functions() {
|
||||||
|
return $GLOBALS['_wp_spl_autoloaders'];
|
||||||
|
}
|
||||||
|
endif;
|
||||||
|
Loading…
Reference in New Issue
Block a user