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.

Built from https://develop.svn.wordpress.org/trunk@37636


git-svn-id: http://core.svn.wordpress.org/trunk@37604 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Ryan McCue 2016-06-06 03:24:29 +00:00
parent d8357b76c5
commit 0def38c30b
3 changed files with 86 additions and 30 deletions

View File

@ -29,35 +29,10 @@ function wp_simplepie_autoload( $class ) {
include( $file );
}
if ( function_exists( 'spl_autoload_register' ) ) {
/**
* 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' );
} 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';
}
/**
* We autoload classes we may not need.
*/
spl_autoload_register( 'wp_simplepie_autoload' );
/**
* SimplePie

View File

@ -434,3 +434,84 @@ if ( ! interface_exists( 'JsonSerializable' ) ) {
if ( ! function_exists( 'random_int' ) ) {
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;

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.6-alpha-37635';
$wp_version = '4.6-alpha-37636';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.