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-handler.php +147 -0 16.2-beta → 16.3 View file →
@@ -1,0 +1,147 @@
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 +use Automattic\Jetpack\Autoloader\AutoloadGenerator;
13 +
14 +/**
15 + * This class selects the package version for the autoloader.
16 + */
17 +class Autoloader_Handler {
18 +
19 + /**
20 + * The PHP_Autoloader instance.
21 + *
22 + * @var PHP_Autoloader
23 + */
24 + private $php_autoloader;
25 +
26 + /**
27 + * The Hook_Manager instance.
28 + *
29 + * @var Hook_Manager
30 + */
31 + private $hook_manager;
32 +
33 + /**
34 + * The Manifest_Reader instance.
35 + *
36 + * @var Manifest_Reader
37 + */
38 + private $manifest_reader;
39 +
40 + /**
41 + * The Version_Selector instance.
42 + *
43 + * @var Version_Selector
44 + */
45 + private $version_selector;
46 +
47 + /**
48 + * The constructor.
49 + *
50 + * @param PHP_Autoloader $php_autoloader The PHP_Autoloader instance.
51 + * @param Hook_Manager $hook_manager The Hook_Manager instance.
52 + * @param Manifest_Reader $manifest_reader The Manifest_Reader instance.
53 + * @param Version_Selector $version_selector The Version_Selector instance.
54 + */
55 + public function __construct( $php_autoloader, $hook_manager, $manifest_reader, $version_selector ) {
56 + $this->php_autoloader = $php_autoloader;
57 + $this->hook_manager = $hook_manager;
58 + $this->manifest_reader = $manifest_reader;
59 + $this->version_selector = $version_selector;
60 + }
61 +
62 + /**
63 + * Checks to see whether or not an autoloader is currently in the process of initializing.
64 + *
65 + * @return bool
66 + */
67 + public function is_initializing() {
68 + // If no version has been set it means that no autoloader has started initializing yet.
69 + global $jetpack_autoloader_latest_version;
70 + if ( ! isset( $jetpack_autoloader_latest_version ) ) {
71 + return false;
72 + }
73 +
74 + // When the version is set but the classmap is not it ALWAYS means that this is the
75 + // latest autoloader and is being included by an older one.
76 + global $jetpack_packages_classmap;
77 + if ( empty( $jetpack_packages_classmap ) ) {
78 + return true;
79 + }
80 +
81 + // Version 2.4.0 added a new global and altered the reset semantics. We need to check
82 + // the other global as well since it may also point at initialization.
83 + // Note: We don't need to check for the class first because every autoloader that
84 + // will set the latest version global requires this class in the classmap.
85 + $replacing_version = $jetpack_packages_classmap[ AutoloadGenerator::class ]['version'];
86 + if ( $this->version_selector->is_dev_version( $replacing_version ) || version_compare( $replacing_version, '2.4.0.0', '>=' ) ) {
87 + global $jetpack_autoloader_loader;
88 + if ( ! isset( $jetpack_autoloader_loader ) ) {
89 + return true;
90 + }
91 + }
92 +
93 + return false;
94 + }
95 +
96 + /**
97 + * Activates an autoloader using the given plugins and activates it.
98 + *
99 + * @param string[] $plugins The plugins to initialize the autoloader for.
100 + */
101 + public function activate_autoloader( $plugins ) {
102 + global $jetpack_packages_psr4;
103 + $jetpack_packages_psr4 = array();
104 + $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_psr4.php', $jetpack_packages_psr4 );
105 +
106 + global $jetpack_packages_classmap;
107 + $jetpack_packages_classmap = array();
108 + $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_classmap.php', $jetpack_packages_classmap );
109 +
110 + global $jetpack_packages_filemap;
111 + $jetpack_packages_filemap = array();
112 + $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_filemap.php', $jetpack_packages_filemap );
113 +
114 + $loader = new Version_Loader(
115 + $this->version_selector,
116 + $jetpack_packages_classmap,
117 + $jetpack_packages_psr4,
118 + $jetpack_packages_filemap
119 + );
120 +
121 + $this->php_autoloader->register_autoloader( $loader );
122 +
123 + // Now that the autoloader is active we can load the filemap.
124 + $loader->load_filemap();
125 + }
126 +
127 + /**
128 + * Resets the active autoloader and all related global state.
129 + */
130 + public function reset_autoloader() {
131 + $this->php_autoloader->unregister_autoloader();
132 + $this->hook_manager->reset();
133 +
134 + // Clear all of the autoloader globals so that older autoloaders don't do anything strange.
135 + global $jetpack_autoloader_latest_version;
136 + $jetpack_autoloader_latest_version = null;
137 +
138 + global $jetpack_packages_classmap;
139 + $jetpack_packages_classmap = array(); // Must be array to avoid exceptions in old autoloaders!
140 +
141 + global $jetpack_packages_psr4;
142 + $jetpack_packages_psr4 = array(); // Must be array to avoid exceptions in old autoloaders!
143 +
144 + global $jetpack_packages_filemap;
145 + $jetpack_packages_filemap = array(); // Must be array to avoid exceptions in old autoloaders!
146 + }
147 +}