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-autoloader.php
55 lines
| 1 | <?php |
| 2 | namespace Automattic\Jetpack\Autoloader\jp2769184bc03a099ec6f4dce25a325723\al5_0_8; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | // phpcs:ignore |
| 5 | class Autoloader { |
| 6 | public static function init( $container = null ) { |
| 7 | // The container holds and manages the lifecycle of our dependencies |
| 8 | // to make them easier to work with and increase flexibility. |
| 9 | if ( ! isset( $container ) ) { |
| 10 | require_once __DIR__ . '/class-container.php'; |
| 11 | $container = new Container(); |
| 12 | } |
| 13 | // phpcs:disable Generic.Commenting.DocComment.MissingShort |
| 14 | $autoloader_handler = $container->get( Autoloader_Handler::class ); |
| 15 | // If the autoloader is already initializing it means that it has included us as the latest. |
| 16 | $was_included_by_autoloader = $autoloader_handler->is_initializing(); |
| 17 | $plugin_locator = $container->get( Plugin_Locator::class ); |
| 18 | $plugins_handler = $container->get( Plugins_Handler::class ); |
| 19 | // The current plugin is the one that we are attempting to initialize here. |
| 20 | $current_plugin = $plugin_locator->find_current_plugin(); |
| 21 | // The active plugins are those that we were able to discover on the site. This list will not |
| 22 | // include mu-plugins, those activated by code, or those who are hidden by filtering. We also |
| 23 | // want to take care to not consider the current plugin unknown if it was included by an |
| 24 | // autoloader. This avoids the case where a plugin will be marked "active" while deactivated |
| 25 | // due to it having the latest autoloader. |
| 26 | $active_plugins = $plugins_handler->get_active_plugins( true, ! $was_included_by_autoloader ); |
| 27 | // The cached plugins are all of those that were active or discovered by the autoloader during a previous request. |
| 28 | // Note that it's possible this list will include plugins that have since been deactivated, but after a request |
| 29 | // the cache should be updated and the deactivated plugins will be removed. |
| 30 | $cached_plugins = $plugins_handler->get_cached_plugins(); |
| 31 | // We combine the active list and cached list to preemptively load classes for plugins that are |
| 32 | // presently unknown but will be loaded during the request. While this may result in us considering packages in |
| 33 | // deactivated plugins there shouldn't be any problems as a result and the eventual consistency is sufficient. |
| 34 | $all_plugins = array_merge( $active_plugins, $cached_plugins ); |
| 35 | // In particular we also include the current plugin to address the case where it is the latest autoloader |
| 36 | // but also unknown (and not cached). We don't want it in the active list because we don't know that it |
| 37 | // is active but we need it in the all plugins list so that it is considered by the autoloader. |
| 38 | $all_plugins[] = $current_plugin; |
| 39 | // We require uniqueness in the array to avoid processing the same plugin more than once. |
| 40 | $all_plugins = array_values( array_unique( $all_plugins ) ); |
| 41 | $guard = $container->get( Latest_Autoloader_Guard::class ); |
| 42 | if ( $guard->should_stop_init( $current_plugin, $all_plugins, $was_included_by_autoloader ) ) { |
| 43 | return; |
| 44 | } |
| 45 | // Initialize the autoloader using the handler now that we're ready. |
| 46 | $autoloader_handler->activate_autoloader( $all_plugins ); |
| 47 | $hook_manager = $container->get( Hook_Manager::class ); |
| 48 | // Register a shutdown handler to clean up the autoloader. |
| 49 | $hook_manager->add_action( 'shutdown', new Shutdown_Handler( $plugins_handler, $cached_plugins, $was_included_by_autoloader ) ); |
| 50 | // Register a plugins_loaded handler to check for conflicting autoloaders. |
| 51 | $hook_manager->add_action( 'plugins_loaded', array( $guard, 'check_for_conflicting_autoloaders' ), 1 ); |
| 52 | // phpcs:enable Generic.Commenting.DocComment.MissingShort |
| 53 | } |
| 54 | } |
| 55 |