class-autoloader-handler.php
1 week ago
class-autoloader-locator.php
1 week ago
class-autoloader.php
1 week ago
class-container.php
1 week ago
class-hook-manager.php
1 week ago
class-latest-autoloader-guard.php
1 week ago
class-manifest-reader.php
1 week ago
class-path-processor.php
1 week ago
class-php-autoloader.php
1 week ago
class-plugin-locator.php
1 week ago
class-plugins-handler.php
1 week ago
class-shutdown-handler.php
1 week ago
class-version-loader.php
1 week ago
class-version-selector.php
1 week ago
index.php
11 months ago
class-php-autoloader.php
67 lines
| 1 | <?php |
| 2 | namespace Automattic\Jetpack\Autoloader\jp2769184bc03a099ec6f4dce25a325723\al5_0_8; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | // phpcs:ignore |
| 5 | class PHP_Autoloader { |
| 6 | public function register_autoloader( $version_loader ) { |
| 7 | // Make sure no other autoloaders are registered. |
| 8 | $this->unregister_autoloader(); |
| 9 | // Set the global so that it can be used to load classes. |
| 10 | global $jetpack_autoloader_loader; |
| 11 | $jetpack_autoloader_loader = $version_loader; |
| 12 | // Ensure that the autoloader is first to avoid contention with others. |
| 13 | spl_autoload_register( array( self::class, 'load_class' ), true, true ); |
| 14 | } |
| 15 | public function unregister_autoloader() { |
| 16 | // Remove any v2 autoloader that we've already registered. |
| 17 | $autoload_chain = spl_autoload_functions(); |
| 18 | if ( ! $autoload_chain ) { |
| 19 | return; |
| 20 | } |
| 21 | foreach ( $autoload_chain as $autoloader ) { |
| 22 | // We can identify a v2 autoloader using the namespace. |
| 23 | $namespace_check = null; |
| 24 | // Functions are recorded as strings. |
| 25 | if ( is_string( $autoloader ) ) { |
| 26 | $namespace_check = $autoloader; |
| 27 | } elseif ( is_array( $autoloader ) && is_string( $autoloader[0] ) ) { |
| 28 | // Static method calls have the class as the first array element. |
| 29 | $namespace_check = $autoloader[0]; |
| 30 | } else { |
| 31 | // Since the autoloader has only ever been a function or a static method we don't currently need to check anything else. |
| 32 | continue; |
| 33 | } |
| 34 | // Check for the namespace without the generated suffix. |
| 35 | if ( 'Automattic\\Jetpack\\Autoloader\\jp' === substr( $namespace_check, 0, 32 ) ) { |
| 36 | spl_autoload_unregister( $autoloader ); |
| 37 | } |
| 38 | } |
| 39 | // Clear the global now that the autoloader has been unregistered. |
| 40 | global $jetpack_autoloader_loader; |
| 41 | $jetpack_autoloader_loader = null; |
| 42 | } |
| 43 | public static function load_class( $class_name ) { |
| 44 | global $jetpack_autoloader_loader; |
| 45 | if ( ! isset( $jetpack_autoloader_loader ) ) { |
| 46 | return false; |
| 47 | } |
| 48 | $file = $jetpack_autoloader_loader->find_class_file( $class_name ); |
| 49 | if ( ! isset( $file ) ) { |
| 50 | return false; |
| 51 | } |
| 52 | // A common source of strange and confusing problems is when a vendor |
| 53 | // file is autoloaded before all plugins have had a chance to register |
| 54 | // with the autoloader. Detect that, if a development constant is set. |
| 55 | if ( defined( 'JETPACK_AUTOLOAD_DEBUG_EARLY_LOADS' ) && JETPACK_AUTOLOAD_DEBUG_EARLY_LOADS && |
| 56 | ( strpos( $file, '/vendor/' ) !== false || strpos( $file, '/jetpack_vendor/' ) !== false ) && |
| 57 | is_callable( 'did_action' ) && ! did_action( 'plugins_loaded' ) |
| 58 | ) { |
| 59 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_wp_debug_backtrace_summary -- This is a debug log message. |
| 60 | $msg = "Jetpack Autoloader: Autoloading `$class_name` before the plugins_loaded hook may cause strange and confusing problems. " . wp_debug_backtrace_summary( '', 1 ); |
| 61 | wp_trigger_error( '', $msg ); |
| 62 | } |
| 63 | require $file; |
| 64 | return true; |
| 65 | } |
| 66 | } |
| 67 |