Нема описа

class-latest-autoloader-guard.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 ensures that we're only executing the latest autoloader.
  11. */
  12. class Latest_Autoloader_Guard {
  13. /**
  14. * The Plugins_Handler instance.
  15. *
  16. * @var Plugins_Handler
  17. */
  18. private $plugins_handler;
  19. /**
  20. * The Autoloader_Handler instance.
  21. *
  22. * @var Autoloader_Handler
  23. */
  24. private $autoloader_handler;
  25. /**
  26. * The Autoloader_locator instance.
  27. *
  28. * @var Autoloader_Locator
  29. */
  30. private $autoloader_locator;
  31. /**
  32. * The constructor.
  33. *
  34. * @param Plugins_Handler $plugins_handler The Plugins_Handler instance.
  35. * @param Autoloader_Handler $autoloader_handler The Autoloader_Handler instance.
  36. * @param Autoloader_Locator $autoloader_locator The Autoloader_Locator instance.
  37. */
  38. public function __construct( $plugins_handler, $autoloader_handler, $autoloader_locator ) {
  39. $this->plugins_handler = $plugins_handler;
  40. $this->autoloader_handler = $autoloader_handler;
  41. $this->autoloader_locator = $autoloader_locator;
  42. }
  43. /**
  44. * Indicates whether or not the autoloader should be initialized. Note that this function
  45. * has the side-effect of actually loading the latest autoloader in the event that this
  46. * is not it.
  47. *
  48. * @param string $current_plugin The current plugin we're checking.
  49. * @param string[] $plugins The active plugins to check for autoloaders in.
  50. * @param bool $was_included_by_autoloader Indicates whether or not this autoloader was included by another.
  51. *
  52. * @return bool True if we should stop initialization, otherwise false.
  53. */
  54. public function should_stop_init( $current_plugin, $plugins, $was_included_by_autoloader ) {
  55. global $jetpack_autoloader_latest_version;
  56. // We need to reset the autoloader when the plugins change because
  57. // that means the autoloader was generated with a different list.
  58. if ( $this->plugins_handler->have_plugins_changed( $plugins ) ) {
  59. $this->autoloader_handler->reset_autoloader();
  60. }
  61. // When the latest autoloader has already been found we don't need to search for it again.
  62. // We should take care however because this will also trigger if the autoloader has been
  63. // included by an older one.
  64. if ( isset( $jetpack_autoloader_latest_version ) && ! $was_included_by_autoloader ) {
  65. return true;
  66. }
  67. $latest_plugin = $this->autoloader_locator->find_latest_autoloader( $plugins, $jetpack_autoloader_latest_version );
  68. if ( isset( $latest_plugin ) && $latest_plugin !== $current_plugin ) {
  69. require $this->autoloader_locator->get_autoloader_path( $latest_plugin );
  70. return true;
  71. }
  72. return false;
  73. }
  74. }