Açıklama Yok

class-autoloader-handler.php 4.5KB

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