1 | <?php |
||
9 | class Autoloader_Handler { |
||
10 | |||
11 | /** |
||
12 | * The PHP_Autoloader instance. |
||
13 | * |
||
14 | * @var PHP_Autoloader |
||
15 | */ |
||
16 | private $php_autoloader; |
||
17 | |||
18 | /** |
||
19 | * The Hook_Manager instance. |
||
20 | * |
||
21 | * @var Hook_Manager |
||
22 | */ |
||
23 | private $hook_manager; |
||
24 | |||
25 | /** |
||
26 | * The Manifest_Reader instance. |
||
27 | * |
||
28 | * @var Manifest_Reader |
||
29 | */ |
||
30 | private $manifest_reader; |
||
31 | |||
32 | /** |
||
33 | * The Version_Selector instance. |
||
34 | * |
||
35 | * @var Version_Selector |
||
36 | */ |
||
37 | private $version_selector; |
||
38 | |||
39 | /** |
||
40 | * The constructor. |
||
41 | * |
||
42 | * @param PHP_Autoloader $php_autoloader The PHP_Autoloader instance. |
||
43 | * @param Hook_Manager $hook_manager The Hook_Manager instance. |
||
44 | * @param Manifest_Reader $manifest_reader The Manifest_Reader instance. |
||
45 | * @param Version_Selector $version_selector The Version_Selector instance. |
||
46 | */ |
||
47 | public function __construct( $php_autoloader, $hook_manager, $manifest_reader, $version_selector ) { |
||
53 | |||
54 | /** |
||
55 | * Checks to see whether or not an autoloader is currently in the process of initializing. |
||
56 | * |
||
57 | * @return bool |
||
58 | */ |
||
59 | public function is_initializing() { |
||
60 | // If no version has been set it means that no autoloader has started initializing yet. |
||
61 | global $jetpack_autoloader_latest_version; |
||
62 | if ( ! isset( $jetpack_autoloader_latest_version ) ) { |
||
63 | return false; |
||
64 | } |
||
65 | |||
66 | // When the version is set but the classmap is not it ALWAYS means that this is the |
||
67 | // latest autoloader and is being included by an older one. |
||
68 | global $jetpack_packages_classmap; |
||
69 | if ( empty( $jetpack_packages_classmap ) ) { |
||
70 | return true; |
||
71 | } |
||
72 | |||
73 | // Version 2.4.0 added a new global and altered the reset semantics. We need to check |
||
74 | // the other global as well since it may also point at initialization. |
||
75 | // Note: We don't need to check for the class first because every autoloader that |
||
76 | // will set the latest version global requires this class in the classmap. |
||
77 | $replacing_version = $jetpack_packages_classmap[ AutoloadGenerator::class ]['version']; |
||
78 | if ( $this->version_selector->is_dev_version( $replacing_version ) || version_compare( $replacing_version, '2.4.0.0', '>=' ) ) { |
||
79 | global $jetpack_autoloader_loader; |
||
80 | if ( ! isset( $jetpack_autoloader_loader ) ) { |
||
81 | return true; |
||
82 | } |
||
83 | } |
||
84 | |||
85 | return false; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Activates an autoloader using the given plugins and activates it. |
||
90 | * |
||
91 | * @param string[] $plugins The plugins to initialize the autoloader for. |
||
92 | */ |
||
93 | public function activate_autoloader( $plugins ) { |
||
118 | |||
119 | /** |
||
120 | * Resets the active autoloader and all related global state. |
||
121 | */ |
||
122 | public function reset_autoloader() { |
||
139 | } |
||
140 |