PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
← All changes | vendor/jetpack-autoloader/class-autoloader.php +93 -0 16.2-beta → 16.3 View file →
@@ -1,0 +1,93 @@
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\jpf11009ded9fc4592b6a05b61ce272b3c_jetpackⓥ16_3\al6_0_1;
9 +
10 + // phpcs:ignore
11 +
12 +/**
13 + * This class handles management of the actual PHP autoloader.
14 + */
15 +class Autoloader {
16 +
17 + /**
18 + * Checks to see whether or not the autoloader should be initialized and then initializes it if so.
19 + *
20 + * @param Container|null $container The container we want to use for autoloader initialization. If none is given
21 + * then a container will be created automatically.
22 + */
23 + public static function init( $container = null ) {
24 + // The container holds and manages the lifecycle of our dependencies
25 + // to make them easier to work with and increase flexibility.
26 + if ( ! isset( $container ) ) {
27 + require_once __DIR__ . '/class-container.php';
28 + $container = new Container();
29 + }
30 +
31 + // phpcs:disable Generic.Commenting.DocComment.MissingShort
32 +
33 + /** @var Autoloader_Handler $autoloader_handler */
34 + $autoloader_handler = $container->get( Autoloader_Handler::class );
35 +
36 + // If the autoloader is already initializing it means that it has included us as the latest.
37 + $was_included_by_autoloader = $autoloader_handler->is_initializing();
38 +
39 + /** @var Plugin_Locator $plugin_locator */
40 + $plugin_locator = $container->get( Plugin_Locator::class );
41 +
42 + /** @var Plugins_Handler $plugins_handler */
43 + $plugins_handler = $container->get( Plugins_Handler::class );
44 +
45 + // The current plugin is the one that we are attempting to initialize here.
46 + $current_plugin = $plugin_locator->find_current_plugin();
47 +
48 + // The active plugins are those that we were able to discover on the site. This list will not
49 + // include mu-plugins, those activated by code, or those who are hidden by filtering. We also
50 + // want to take care to not consider the current plugin unknown if it was included by an
51 + // autoloader. This avoids the case where a plugin will be marked "active" while deactivated
52 + // due to it having the latest autoloader.
53 + $active_plugins = $plugins_handler->get_active_plugins( true, ! $was_included_by_autoloader );
54 +
55 + // The cached plugins are all of those that were active or discovered by the autoloader during a previous request.
56 + // Note that it's possible this list will include plugins that have since been deactivated, but after a request
57 + // the cache should be updated and the deactivated plugins will be removed.
58 + $cached_plugins = $plugins_handler->get_cached_plugins();
59 +
60 + // We combine the active list and cached list to preemptively load classes for plugins that are
61 + // presently unknown but will be loaded during the request. While this may result in us considering packages in
62 + // deactivated plugins there shouldn't be any problems as a result and the eventual consistency is sufficient.
63 + // The current plugin is included to cover the case where it is the latest autoloader but unknown (and not
64 + // cached). It goes ahead of the cached entries because manifests are read in order and ties go to the first
65 + // read: a cached path can name a build a host just retired, which must not outrank the directory we are
66 + // executing from. Do not move it ahead of the active entries, which would give each plugin a differently
67 + // ordered list and trip the order-sensitive comparison in have_plugins_changed().
68 + $all_plugins = array_merge( $active_plugins, array( $current_plugin ), $cached_plugins );
69 +
70 + // We require uniqueness in the array to avoid processing the same plugin more than once.
71 + $all_plugins = array_values( array_unique( $all_plugins ) );
72 +
73 + /** @var Latest_Autoloader_Guard $guard */
74 + $guard = $container->get( Latest_Autoloader_Guard::class );
75 + if ( $guard->should_stop_init( $current_plugin, $all_plugins, $was_included_by_autoloader ) ) {
76 + return;
77 + }
78 +
79 + // Initialize the autoloader using the handler now that we're ready.
80 + $autoloader_handler->activate_autoloader( $all_plugins );
81 +
82 + /** @var Hook_Manager $hook_manager */
83 + $hook_manager = $container->get( Hook_Manager::class );
84 +
85 + // Register a shutdown handler to clean up the autoloader.
86 + $hook_manager->add_action( 'shutdown', new Shutdown_Handler( $plugins_handler, $cached_plugins, $was_included_by_autoloader ) );
87 +
88 + // Register a plugins_loaded handler to check for conflicting autoloaders.
89 + $hook_manager->add_action( 'plugins_loaded', array( $guard, 'check_for_conflicting_autoloaders' ), 1 );
90 +
91 + // phpcs:enable Generic.Commenting.DocComment.MissingShort
92 + }
93 +}