Нет описания

class-container.php 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. /**
  10. * This class manages the files and dependencies of the autoloader.
  11. */
  12. class Container {
  13. /**
  14. * Since each autoloader's class files exist within their own namespace we need a map to
  15. * convert between the local class and a shared key. Note that no version checking is
  16. * performed on these dependencies and the first autoloader to register will be the
  17. * one that is utilized.
  18. */
  19. const SHARED_DEPENDENCY_KEYS = array(
  20. Hook_Manager::class => 'Hook_Manager',
  21. );
  22. /**
  23. * A map of all the dependencies we've registered with the container and created.
  24. *
  25. * @var array
  26. */
  27. protected $dependencies;
  28. /**
  29. * The constructor.
  30. */
  31. public function __construct() {
  32. $this->dependencies = array();
  33. $this->register_shared_dependencies();
  34. $this->register_dependencies();
  35. $this->initialize_globals();
  36. }
  37. /**
  38. * Gets a dependency out of the container.
  39. *
  40. * @param string $class The class to fetch.
  41. *
  42. * @return mixed
  43. * @throws \InvalidArgumentException When a class that isn't registered with the container is fetched.
  44. */
  45. public function get( $class ) {
  46. if ( ! isset( $this->dependencies[ $class ] ) ) {
  47. throw new \InvalidArgumentException( "Class '$class' is not registered with the container." );
  48. }
  49. return $this->dependencies[ $class ];
  50. }
  51. /**
  52. * Registers all of the dependencies that are shared between all instances of the autoloader.
  53. */
  54. private function register_shared_dependencies() {
  55. global $jetpack_autoloader_container_shared;
  56. if ( ! isset( $jetpack_autoloader_container_shared ) ) {
  57. $jetpack_autoloader_container_shared = array();
  58. }
  59. $key = self::SHARED_DEPENDENCY_KEYS[ Hook_Manager::class ];
  60. if ( ! isset( $jetpack_autoloader_container_shared[ $key ] ) ) {
  61. require_once __DIR__ . '/class-hook-manager.php';
  62. $jetpack_autoloader_container_shared[ $key ] = new Hook_Manager();
  63. }
  64. $this->dependencies[ Hook_Manager::class ] = &$jetpack_autoloader_container_shared[ $key ];
  65. }
  66. /**
  67. * Registers all of the dependencies with the container.
  68. */
  69. private function register_dependencies() {
  70. require_once __DIR__ . '/class-path-processor.php';
  71. $this->dependencies[ Path_Processor::class ] = new Path_Processor();
  72. require_once __DIR__ . '/class-plugin-locator.php';
  73. $this->dependencies[ Plugin_Locator::class ] = new Plugin_Locator(
  74. $this->get( Path_Processor::class )
  75. );
  76. require_once __DIR__ . '/class-version-selector.php';
  77. $this->dependencies[ Version_Selector::class ] = new Version_Selector();
  78. require_once __DIR__ . '/class-autoloader-locator.php';
  79. $this->dependencies[ Autoloader_Locator::class ] = new Autoloader_Locator(
  80. $this->get( Version_Selector::class )
  81. );
  82. require_once __DIR__ . '/class-php-autoloader.php';
  83. $this->dependencies[ PHP_Autoloader::class ] = new PHP_Autoloader();
  84. require_once __DIR__ . '/class-manifest-reader.php';
  85. $this->dependencies[ Manifest_Reader::class ] = new Manifest_Reader(
  86. $this->get( Version_Selector::class )
  87. );
  88. require_once __DIR__ . '/class-plugins-handler.php';
  89. $this->dependencies[ Plugins_Handler::class ] = new Plugins_Handler(
  90. $this->get( Plugin_Locator::class ),
  91. $this->get( Path_Processor::class )
  92. );
  93. require_once __DIR__ . '/class-autoloader-handler.php';
  94. $this->dependencies[ Autoloader_Handler::class ] = new Autoloader_Handler(
  95. $this->get( PHP_Autoloader::class ),
  96. $this->get( Hook_Manager::class ),
  97. $this->get( Manifest_Reader::class ),
  98. $this->get( Version_Selector::class )
  99. );
  100. require_once __DIR__ . '/class-latest-autoloader-guard.php';
  101. $this->dependencies[ Latest_Autoloader_Guard::class ] = new Latest_Autoloader_Guard(
  102. $this->get( Plugins_Handler::class ),
  103. $this->get( Autoloader_Handler::class ),
  104. $this->get( Autoloader_Locator::class )
  105. );
  106. // Register any classes that we will use elsewhere.
  107. require_once __DIR__ . '/class-version-loader.php';
  108. require_once __DIR__ . '/class-shutdown-handler.php';
  109. }
  110. /**
  111. * Initializes any of the globals needed by the autoloader.
  112. */
  113. private function initialize_globals() {
  114. /*
  115. * This global was retired in version 2.9. The value is set to 'false' to maintain
  116. * compatibility with older versions of the autoloader.
  117. */
  118. global $jetpack_autoloader_including_latest;
  119. $jetpack_autoloader_including_latest = false;
  120. // Not all plugins can be found using the locator. In cases where a plugin loads the autoloader
  121. // but was not discoverable, we will record them in this array to track them as "active".
  122. global $jetpack_autoloader_activating_plugins_paths;
  123. if ( ! isset( $jetpack_autoloader_activating_plugins_paths ) ) {
  124. $jetpack_autoloader_activating_plugins_paths = array();
  125. }
  126. }
  127. }