| 1 |
<?php |
| 2 |
/** |
| 3 |
* This file was automatically generated by automattic/jetpack-autoloader. |
| 4 |
* |
| 5 |
* @package automattic/jetpack-autoloader |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Automattic\Jetpack\Autoloader\jpf9a0c10d6df9f7b5fef232f74cadcb58\al5_0_7; |
| 9 |
|
| 10 |
// phpcs:ignore |
| 11 |
|
| 12 |
/** |
| 13 |
* This class handles management of the actual PHP autoloader. |
| 14 |
*/ |
| 15 |
class PHP_Autoloader { |
| 16 |
|
| 17 |
/** |
| 18 |
* Registers the autoloader with PHP so that it can begin autoloading classes. |
| 19 |
* |
| 20 |
* @param Version_Loader $version_loader The class loader to use in the autoloader. |
| 21 |
*/ |
| 22 |
public function register_autoloader( $version_loader ) { |
| 23 |
// Make sure no other autoloaders are registered. |
| 24 |
$this->unregister_autoloader(); |
| 25 |
|
| 26 |
// Set the global so that it can be used to load classes. |
| 27 |
global $jetpack_autoloader_loader; |
| 28 |
$jetpack_autoloader_loader = $version_loader; |
| 29 |
|
| 30 |
// Ensure that the autoloader is first to avoid contention with others. |
| 31 |
spl_autoload_register( array( self::class, 'load_class' ), true, true ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Unregisters the active autoloader so that it will no longer autoload classes. |
| 36 |
*/ |
| 37 |
public function unregister_autoloader() { |
| 38 |
// Remove any v2 autoloader that we've already registered. |
| 39 |
$autoload_chain = spl_autoload_functions(); |
| 40 |
if ( ! $autoload_chain ) { |
| 41 |
return; |
| 42 |
} |
| 43 |
foreach ( $autoload_chain as $autoloader ) { |
| 44 |
// We can identify a v2 autoloader using the namespace. |
| 45 |
$namespace_check = null; |
| 46 |
|
| 47 |
// Functions are recorded as strings. |
| 48 |
if ( is_string( $autoloader ) ) { |
| 49 |
$namespace_check = $autoloader; |
| 50 |
} elseif ( is_array( $autoloader ) && is_string( $autoloader[0] ) ) { |
| 51 |
// Static method calls have the class as the first array element. |
| 52 |
$namespace_check = $autoloader[0]; |
| 53 |
} else { |
| 54 |
// Since the autoloader has only ever been a function or a static method we don't currently need to check anything else. |
| 55 |
continue; |
| 56 |
} |
| 57 |
|
| 58 |
// Check for the namespace without the generated suffix. |
| 59 |
if ( 'Automattic\\Jetpack\\Autoloader\\jp' === substr( $namespace_check, 0, 32 ) ) { |
| 60 |
spl_autoload_unregister( $autoloader ); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
// Clear the global now that the autoloader has been unregistered. |
| 65 |
global $jetpack_autoloader_loader; |
| 66 |
$jetpack_autoloader_loader = null; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Loads a class file if one could be found. |
| 71 |
* |
| 72 |
* Note: This function is static so that the autoloader can be easily unregistered. If |
| 73 |
* it was a class method we would have to unwrap the object to check the namespace. |
| 74 |
* |
| 75 |
* @param string $class_name The name of the class to autoload. |
| 76 |
* |
| 77 |
* @return bool Indicates whether or not a class file was loaded. |
| 78 |
*/ |
| 79 |
public static function load_class( $class_name ) { |
| 80 |
global $jetpack_autoloader_loader; |
| 81 |
if ( ! isset( $jetpack_autoloader_loader ) ) { |
| 82 |
return false; |
| 83 |
} |
| 84 |
|
| 85 |
$file = $jetpack_autoloader_loader->find_class_file( $class_name ); |
| 86 |
if ( ! isset( $file ) ) { |
| 87 |
return false; |
| 88 |
} |
| 89 |
|
| 90 |
// A common source of strange and confusing problems is when a vendor |
| 91 |
// file is autoloaded before all plugins have had a chance to register |
| 92 |
// with the autoloader. Detect that, if a development constant is set. |
| 93 |
if ( defined( 'JETPACK_AUTOLOAD_DEBUG_EARLY_LOADS' ) && JETPACK_AUTOLOAD_DEBUG_EARLY_LOADS && |
| 94 |
( strpos( $file, '/vendor/' ) !== false || strpos( $file, '/jetpack_vendor/' ) !== false ) && |
| 95 |
is_callable( 'did_action' ) && ! did_action( 'plugins_loaded' ) |
| 96 |
) { |
| 97 |
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_wp_debug_backtrace_summary -- This is a debug log message. |
| 98 |
$msg = "Jetpack Autoloader: Autoloading `$class_name` before the plugins_loaded hook may cause strange and confusing problems. " . wp_debug_backtrace_summary( '', 1 ); |
| 99 |
wp_trigger_error( '', $msg ); |
| 100 |
} |
| 101 |
|
| 102 |
require $file; |
| 103 |
return true; |
| 104 |
} |
| 105 |
} |
| 106 |
|