kollapsminoriteten/wp-content/plugins/jetpack/vendor/jetpack-autoloader/class-autoloader-handler.php

148 lines
4.5 KiB
PHP
Raw Normal View History

2020-10-20 18:05:12 +02:00
<?php
/**
* This file was automatically generated by automattic/jetpack-autoloader.
*
* @package automattic/jetpack-autoloader
*/
2022-12-15 17:41:53 +01:00
namespace Automattic\Jetpack\Autoloader\jpf11009ded9fc4592b6a05b61ce272b3c_jetpackⓥ11_6;
2020-10-20 18:05:12 +02:00
// phpcs:ignore
2021-04-27 08:32:47 +02:00
use Automattic\Jetpack\Autoloader\AutoloadGenerator;
2020-10-20 18:05:12 +02:00
/**
* This class selects the package version for the autoloader.
*/
class Autoloader_Handler {
/**
2021-04-27 08:32:47 +02:00
* The PHP_Autoloader instance.
2020-10-20 18:05:12 +02:00
*
2021-04-27 08:32:47 +02:00
* @var PHP_Autoloader
2020-10-20 18:05:12 +02:00
*/
2021-04-27 08:32:47 +02:00
private $php_autoloader;
2020-10-20 18:05:12 +02:00
/**
2021-04-27 08:32:47 +02:00
* The Hook_Manager instance.
2020-10-20 18:05:12 +02:00
*
2021-04-27 08:32:47 +02:00
* @var Hook_Manager
2020-10-20 18:05:12 +02:00
*/
2021-04-27 08:32:47 +02:00
private $hook_manager;
2020-10-20 18:05:12 +02:00
/**
2021-04-27 08:32:47 +02:00
* The Manifest_Reader instance.
2020-10-20 18:05:12 +02:00
*
2021-04-27 08:32:47 +02:00
* @var Manifest_Reader
2020-10-20 18:05:12 +02:00
*/
2021-04-27 08:32:47 +02:00
private $manifest_reader;
2020-10-20 18:05:12 +02:00
/**
2021-04-27 08:32:47 +02:00
* The Version_Selector instance.
2020-10-20 18:05:12 +02:00
*
* @var Version_Selector
*/
private $version_selector;
/**
* The constructor.
*
2021-04-27 08:32:47 +02:00
* @param PHP_Autoloader $php_autoloader The PHP_Autoloader instance.
* @param Hook_Manager $hook_manager The Hook_Manager instance.
* @param Manifest_Reader $manifest_reader The Manifest_Reader instance.
* @param Version_Selector $version_selector The Version_Selector instance.
2020-10-20 18:05:12 +02:00
*/
2021-04-27 08:32:47 +02:00
public function __construct( $php_autoloader, $hook_manager, $manifest_reader, $version_selector ) {
$this->php_autoloader = $php_autoloader;
$this->hook_manager = $hook_manager;
$this->manifest_reader = $manifest_reader;
$this->version_selector = $version_selector;
2020-10-20 18:05:12 +02:00
}
/**
2021-04-27 08:32:47 +02:00
* Checks to see whether or not an autoloader is currently in the process of initializing.
2020-10-20 18:05:12 +02:00
*
2021-04-27 08:32:47 +02:00
* @return bool
2020-10-20 18:05:12 +02:00
*/
2021-04-27 08:32:47 +02:00
public function is_initializing() {
// If no version has been set it means that no autoloader has started initializing yet.
2020-10-20 18:05:12 +02:00
global $jetpack_autoloader_latest_version;
2021-04-27 08:32:47 +02:00
if ( ! isset( $jetpack_autoloader_latest_version ) ) {
return false;
2020-10-20 18:05:12 +02:00
}
2021-04-27 08:32:47 +02:00
// When the version is set but the classmap is not it ALWAYS means that this is the
// latest autoloader and is being included by an older one.
global $jetpack_packages_classmap;
if ( empty( $jetpack_packages_classmap ) ) {
2020-10-20 18:05:12 +02:00
return true;
}
2021-04-27 08:32:47 +02:00
// Version 2.4.0 added a new global and altered the reset semantics. We need to check
// the other global as well since it may also point at initialization.
// Note: We don't need to check for the class first because every autoloader that
// will set the latest version global requires this class in the classmap.
$replacing_version = $jetpack_packages_classmap[ AutoloadGenerator::class ]['version'];
if ( $this->version_selector->is_dev_version( $replacing_version ) || version_compare( $replacing_version, '2.4.0.0', '>=' ) ) {
global $jetpack_autoloader_loader;
if ( ! isset( $jetpack_autoloader_loader ) ) {
return true;
2020-10-20 18:05:12 +02:00
}
}
2021-04-27 08:32:47 +02:00
return false;
2020-10-20 18:05:12 +02:00
}
/**
2021-04-27 08:32:47 +02:00
* Activates an autoloader using the given plugins and activates it.
2020-10-20 18:05:12 +02:00
*
2021-04-27 08:32:47 +02:00
* @param string[] $plugins The plugins to initialize the autoloader for.
2020-10-20 18:05:12 +02:00
*/
2021-04-27 08:32:47 +02:00
public function activate_autoloader( $plugins ) {
2020-10-20 18:05:12 +02:00
global $jetpack_packages_psr4;
$jetpack_packages_psr4 = array();
2021-04-27 08:32:47 +02:00
$this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_psr4.php', $jetpack_packages_psr4 );
2020-10-20 18:05:12 +02:00
global $jetpack_packages_classmap;
$jetpack_packages_classmap = array();
2021-04-27 08:32:47 +02:00
$this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_classmap.php', $jetpack_packages_classmap );
2020-10-20 18:05:12 +02:00
global $jetpack_packages_filemap;
$jetpack_packages_filemap = array();
2021-04-27 08:32:47 +02:00
$this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_filemap.php', $jetpack_packages_filemap );
2020-10-20 18:05:12 +02:00
2021-04-27 08:32:47 +02:00
$loader = new Version_Loader(
2020-10-20 18:05:12 +02:00
$this->version_selector,
$jetpack_packages_classmap,
$jetpack_packages_psr4,
$jetpack_packages_filemap
);
2021-04-27 08:32:47 +02:00
$this->php_autoloader->register_autoloader( $loader );
// Now that the autoloader is active we can load the filemap.
$loader->load_filemap();
2020-10-20 18:05:12 +02:00
}
/**
2021-04-27 08:32:47 +02:00
* Resets the active autoloader and all related global state.
2020-10-20 18:05:12 +02:00
*/
2021-04-27 08:32:47 +02:00
public function reset_autoloader() {
$this->php_autoloader->unregister_autoloader();
$this->hook_manager->reset();
2020-10-20 18:05:12 +02:00
2021-04-27 08:32:47 +02:00
// Clear all of the autoloader globals so that older autoloaders don't do anything strange.
global $jetpack_autoloader_latest_version;
$jetpack_autoloader_latest_version = null;
global $jetpack_packages_classmap;
$jetpack_packages_classmap = array(); // Must be array to avoid exceptions in old autoloaders!
global $jetpack_packages_psr4;
$jetpack_packages_psr4 = array(); // Must be array to avoid exceptions in old autoloaders!
global $jetpack_packages_filemap;
$jetpack_packages_filemap = array(); // Must be array to avoid exceptions in old autoloaders!
2020-10-20 18:05:12 +02:00
}
}