@@ -7,158 +7,158 @@ |
||
| 7 | 7 | |
| 8 | 8 | namespace Automattic\Jetpack\Autoloader\jp526c9128fcc85a1cd942451999a66eb0; |
| 9 | 9 | |
| 10 | - // phpcs:ignore |
|
| 10 | + // phpcs:ignore |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * This class handles locating and caching all of the active plugins. |
| 14 | 14 | */ |
| 15 | 15 | class Plugins_Handler { |
| 16 | - /** |
|
| 17 | - * The transient key for plugin paths. |
|
| 18 | - */ |
|
| 19 | - const TRANSIENT_KEY = 'jetpack_autoloader_plugin_paths'; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * The locator for finding plugins in different locations. |
|
| 23 | - * |
|
| 24 | - * @var Plugin_Locator |
|
| 25 | - */ |
|
| 26 | - private $plugin_locator; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * The processor for transforming cached paths. |
|
| 30 | - * |
|
| 31 | - * @var Path_Processor |
|
| 32 | - */ |
|
| 33 | - private $path_processor; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * The constructor. |
|
| 37 | - * |
|
| 38 | - * @param Plugin_Locator $plugin_locator The locator for finding active plugins. |
|
| 39 | - * @param Path_Processor $path_processor The processor for transforming cached paths. |
|
| 40 | - */ |
|
| 41 | - public function __construct( $plugin_locator, $path_processor ) { |
|
| 42 | - $this->plugin_locator = $plugin_locator; |
|
| 43 | - $this->path_processor = $path_processor; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Gets all of the active plugins we can find. |
|
| 48 | - * |
|
| 49 | - * @param bool $include_deactivating When true, plugins deactivating this request will be considered active. |
|
| 50 | - * @param bool $record_unknown When true, the current plugin will be marked as active and recorded when unknown. |
|
| 51 | - * |
|
| 52 | - * @return string[] |
|
| 53 | - */ |
|
| 54 | - public function get_active_plugins( $include_deactivating, $record_unknown ) { |
|
| 55 | - global $jetpack_autoloader_activating_plugins_paths; |
|
| 56 | - |
|
| 57 | - // We're going to build a unique list of plugins from a few different sources |
|
| 58 | - // to find all of our "active" plugins. While we need to return an integer |
|
| 59 | - // array, we're going to use an associative array internally to reduce |
|
| 60 | - // the amount of time that we're going to spend checking uniqueness |
|
| 61 | - // and merging different arrays together to form the output. |
|
| 62 | - $active_plugins = array(); |
|
| 63 | - |
|
| 64 | - // Make sure that plugins which have activated this request are considered as "active" even though |
|
| 65 | - // they probably won't be present in any option. |
|
| 66 | - if ( is_array( $jetpack_autoloader_activating_plugins_paths ) ) { |
|
| 67 | - foreach ( $jetpack_autoloader_activating_plugins_paths as $path ) { |
|
| 68 | - $active_plugins[ $path ] = $path; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // This option contains all of the plugins that have been activated. |
|
| 73 | - $plugins = $this->plugin_locator->find_using_option( 'active_plugins' ); |
|
| 74 | - foreach ( $plugins as $path ) { |
|
| 75 | - $active_plugins[ $path ] = $path; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // This option contains all of the multisite plugins that have been activated. |
|
| 79 | - if ( is_multisite() ) { |
|
| 80 | - $plugins = $this->plugin_locator->find_using_option( 'active_sitewide_plugins', true ); |
|
| 81 | - foreach ( $plugins as $path ) { |
|
| 82 | - $active_plugins[ $path ] = $path; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // These actions contain plugins that are being activated/deactivated during this request. |
|
| 87 | - $plugins = $this->plugin_locator->find_using_request_action( array( 'activate', 'activate-selected', 'deactivate', 'deactivate-selected' ) ); |
|
| 88 | - foreach ( $plugins as $path ) { |
|
| 89 | - $active_plugins[ $path ] = $path; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // When the current plugin isn't considered "active" there's a problem. |
|
| 93 | - // Since we're here, the plugin is active and currently being loaded. |
|
| 94 | - // We can support this case (mu-plugins and non-standard activation) |
|
| 95 | - // by adding the current plugin to the active list and marking it |
|
| 96 | - // as an unknown (activating) plugin. This also has the benefit |
|
| 97 | - // of causing a reset because the active plugins list has |
|
| 98 | - // been changed since it was saved in the global. |
|
| 99 | - $current_plugin = $this->plugin_locator->find_current_plugin(); |
|
| 100 | - if ( $record_unknown && ! in_array( $current_plugin, $active_plugins, true ) ) { |
|
| 101 | - $active_plugins[ $current_plugin ] = $current_plugin; |
|
| 102 | - $jetpack_autoloader_activating_plugins_paths[] = $current_plugin; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // When deactivating plugins aren't desired we should entirely remove them from the active list. |
|
| 106 | - if ( ! $include_deactivating ) { |
|
| 107 | - // These actions contain plugins that are being deactivated during this request. |
|
| 108 | - $plugins = $this->plugin_locator->find_using_request_action( array( 'deactivate', 'deactivate-selected' ) ); |
|
| 109 | - foreach ( $plugins as $path ) { |
|
| 110 | - unset( $active_plugins[ $path ] ); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - // Transform the array so that we don't have to worry about the keys interacting with other array types later. |
|
| 115 | - return array_values( $active_plugins ); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Gets all of the cached plugins if there are any. |
|
| 120 | - * |
|
| 121 | - * @return string[] |
|
| 122 | - */ |
|
| 123 | - public function get_cached_plugins() { |
|
| 124 | - $cached = get_transient( self::TRANSIENT_KEY ); |
|
| 125 | - if ( ! is_array( $cached ) || empty( $cached ) ) { |
|
| 126 | - return array(); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // We need to expand the tokens to an absolute path for this webserver. |
|
| 130 | - return array_map( array( $this->path_processor, 'untokenize_path_constants' ), $cached ); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Saves the plugin list to the cache. |
|
| 135 | - * |
|
| 136 | - * @param array $plugins The plugin list to save to the cache. |
|
| 137 | - */ |
|
| 138 | - public function cache_plugins( $plugins ) { |
|
| 139 | - // We store the paths in a tokenized form so that that webservers with different absolute paths don't break. |
|
| 140 | - $plugins = array_map( array( $this->path_processor, 'tokenize_path_constants' ), $plugins ); |
|
| 141 | - |
|
| 142 | - set_transient( self::TRANSIENT_KEY, $plugins ); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Checks to see whether or not the plugin list given has changed when compared to the |
|
| 147 | - * shared `$jetpack_autoloader_cached_plugin_paths` global. This allows us to deal |
|
| 148 | - * with cases where the active list may change due to filtering.. |
|
| 149 | - * |
|
| 150 | - * @param string[] $plugins The plugins list to check against the global cache. |
|
| 151 | - * |
|
| 152 | - * @return bool True if the plugins have changed, otherwise false. |
|
| 153 | - */ |
|
| 154 | - public function have_plugins_changed( $plugins ) { |
|
| 155 | - global $jetpack_autoloader_cached_plugin_paths; |
|
| 156 | - |
|
| 157 | - if ( $jetpack_autoloader_cached_plugin_paths !== $plugins ) { |
|
| 158 | - $jetpack_autoloader_cached_plugin_paths = $plugins; |
|
| 159 | - return true; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - return false; |
|
| 163 | - } |
|
| 16 | + /** |
|
| 17 | + * The transient key for plugin paths. |
|
| 18 | + */ |
|
| 19 | + const TRANSIENT_KEY = 'jetpack_autoloader_plugin_paths'; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * The locator for finding plugins in different locations. |
|
| 23 | + * |
|
| 24 | + * @var Plugin_Locator |
|
| 25 | + */ |
|
| 26 | + private $plugin_locator; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * The processor for transforming cached paths. |
|
| 30 | + * |
|
| 31 | + * @var Path_Processor |
|
| 32 | + */ |
|
| 33 | + private $path_processor; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * The constructor. |
|
| 37 | + * |
|
| 38 | + * @param Plugin_Locator $plugin_locator The locator for finding active plugins. |
|
| 39 | + * @param Path_Processor $path_processor The processor for transforming cached paths. |
|
| 40 | + */ |
|
| 41 | + public function __construct( $plugin_locator, $path_processor ) { |
|
| 42 | + $this->plugin_locator = $plugin_locator; |
|
| 43 | + $this->path_processor = $path_processor; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Gets all of the active plugins we can find. |
|
| 48 | + * |
|
| 49 | + * @param bool $include_deactivating When true, plugins deactivating this request will be considered active. |
|
| 50 | + * @param bool $record_unknown When true, the current plugin will be marked as active and recorded when unknown. |
|
| 51 | + * |
|
| 52 | + * @return string[] |
|
| 53 | + */ |
|
| 54 | + public function get_active_plugins( $include_deactivating, $record_unknown ) { |
|
| 55 | + global $jetpack_autoloader_activating_plugins_paths; |
|
| 56 | + |
|
| 57 | + // We're going to build a unique list of plugins from a few different sources |
|
| 58 | + // to find all of our "active" plugins. While we need to return an integer |
|
| 59 | + // array, we're going to use an associative array internally to reduce |
|
| 60 | + // the amount of time that we're going to spend checking uniqueness |
|
| 61 | + // and merging different arrays together to form the output. |
|
| 62 | + $active_plugins = array(); |
|
| 63 | + |
|
| 64 | + // Make sure that plugins which have activated this request are considered as "active" even though |
|
| 65 | + // they probably won't be present in any option. |
|
| 66 | + if ( is_array( $jetpack_autoloader_activating_plugins_paths ) ) { |
|
| 67 | + foreach ( $jetpack_autoloader_activating_plugins_paths as $path ) { |
|
| 68 | + $active_plugins[ $path ] = $path; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // This option contains all of the plugins that have been activated. |
|
| 73 | + $plugins = $this->plugin_locator->find_using_option( 'active_plugins' ); |
|
| 74 | + foreach ( $plugins as $path ) { |
|
| 75 | + $active_plugins[ $path ] = $path; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // This option contains all of the multisite plugins that have been activated. |
|
| 79 | + if ( is_multisite() ) { |
|
| 80 | + $plugins = $this->plugin_locator->find_using_option( 'active_sitewide_plugins', true ); |
|
| 81 | + foreach ( $plugins as $path ) { |
|
| 82 | + $active_plugins[ $path ] = $path; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // These actions contain plugins that are being activated/deactivated during this request. |
|
| 87 | + $plugins = $this->plugin_locator->find_using_request_action( array( 'activate', 'activate-selected', 'deactivate', 'deactivate-selected' ) ); |
|
| 88 | + foreach ( $plugins as $path ) { |
|
| 89 | + $active_plugins[ $path ] = $path; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // When the current plugin isn't considered "active" there's a problem. |
|
| 93 | + // Since we're here, the plugin is active and currently being loaded. |
|
| 94 | + // We can support this case (mu-plugins and non-standard activation) |
|
| 95 | + // by adding the current plugin to the active list and marking it |
|
| 96 | + // as an unknown (activating) plugin. This also has the benefit |
|
| 97 | + // of causing a reset because the active plugins list has |
|
| 98 | + // been changed since it was saved in the global. |
|
| 99 | + $current_plugin = $this->plugin_locator->find_current_plugin(); |
|
| 100 | + if ( $record_unknown && ! in_array( $current_plugin, $active_plugins, true ) ) { |
|
| 101 | + $active_plugins[ $current_plugin ] = $current_plugin; |
|
| 102 | + $jetpack_autoloader_activating_plugins_paths[] = $current_plugin; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // When deactivating plugins aren't desired we should entirely remove them from the active list. |
|
| 106 | + if ( ! $include_deactivating ) { |
|
| 107 | + // These actions contain plugins that are being deactivated during this request. |
|
| 108 | + $plugins = $this->plugin_locator->find_using_request_action( array( 'deactivate', 'deactivate-selected' ) ); |
|
| 109 | + foreach ( $plugins as $path ) { |
|
| 110 | + unset( $active_plugins[ $path ] ); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + // Transform the array so that we don't have to worry about the keys interacting with other array types later. |
|
| 115 | + return array_values( $active_plugins ); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Gets all of the cached plugins if there are any. |
|
| 120 | + * |
|
| 121 | + * @return string[] |
|
| 122 | + */ |
|
| 123 | + public function get_cached_plugins() { |
|
| 124 | + $cached = get_transient( self::TRANSIENT_KEY ); |
|
| 125 | + if ( ! is_array( $cached ) || empty( $cached ) ) { |
|
| 126 | + return array(); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // We need to expand the tokens to an absolute path for this webserver. |
|
| 130 | + return array_map( array( $this->path_processor, 'untokenize_path_constants' ), $cached ); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Saves the plugin list to the cache. |
|
| 135 | + * |
|
| 136 | + * @param array $plugins The plugin list to save to the cache. |
|
| 137 | + */ |
|
| 138 | + public function cache_plugins( $plugins ) { |
|
| 139 | + // We store the paths in a tokenized form so that that webservers with different absolute paths don't break. |
|
| 140 | + $plugins = array_map( array( $this->path_processor, 'tokenize_path_constants' ), $plugins ); |
|
| 141 | + |
|
| 142 | + set_transient( self::TRANSIENT_KEY, $plugins ); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Checks to see whether or not the plugin list given has changed when compared to the |
|
| 147 | + * shared `$jetpack_autoloader_cached_plugin_paths` global. This allows us to deal |
|
| 148 | + * with cases where the active list may change due to filtering.. |
|
| 149 | + * |
|
| 150 | + * @param string[] $plugins The plugins list to check against the global cache. |
|
| 151 | + * |
|
| 152 | + * @return bool True if the plugins have changed, otherwise false. |
|
| 153 | + */ |
|
| 154 | + public function have_plugins_changed( $plugins ) { |
|
| 155 | + global $jetpack_autoloader_cached_plugin_paths; |
|
| 156 | + |
|
| 157 | + if ( $jetpack_autoloader_cached_plugin_paths !== $plugins ) { |
|
| 158 | + $jetpack_autoloader_cached_plugin_paths = $plugins; |
|
| 159 | + return true; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + return false; |
|
| 163 | + } |
|
| 164 | 164 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @param Plugin_Locator $plugin_locator The locator for finding active plugins. |
| 31 | 31 | * @param Path_Processor $path_processor The processor for transforming cached paths. |
| 32 | 32 | */ |
| 33 | - public function __construct( $plugin_locator, $path_processor ) { |
|
| 33 | + public function __construct($plugin_locator, $path_processor) { |
|
| 34 | 34 | $this->plugin_locator = $plugin_locator; |
| 35 | 35 | $this->path_processor = $path_processor; |
| 36 | 36 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return string[] |
| 45 | 45 | */ |
| 46 | - public function get_active_plugins( $include_deactivating, $record_unknown ) { |
|
| 46 | + public function get_active_plugins($include_deactivating, $record_unknown) { |
|
| 47 | 47 | global $jetpack_autoloader_activating_plugins_paths; |
| 48 | 48 | |
| 49 | 49 | // We're going to build a unique list of plugins from a few different sources |
@@ -55,30 +55,30 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | // Make sure that plugins which have activated this request are considered as "active" even though |
| 57 | 57 | // they probably won't be present in any option. |
| 58 | - if ( is_array( $jetpack_autoloader_activating_plugins_paths ) ) { |
|
| 59 | - foreach ( $jetpack_autoloader_activating_plugins_paths as $path ) { |
|
| 60 | - $active_plugins[ $path ] = $path; |
|
| 58 | + if (is_array($jetpack_autoloader_activating_plugins_paths)) { |
|
| 59 | + foreach ($jetpack_autoloader_activating_plugins_paths as $path) { |
|
| 60 | + $active_plugins[$path] = $path; |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | // This option contains all of the plugins that have been activated. |
| 65 | - $plugins = $this->plugin_locator->find_using_option( 'active_plugins' ); |
|
| 66 | - foreach ( $plugins as $path ) { |
|
| 67 | - $active_plugins[ $path ] = $path; |
|
| 65 | + $plugins = $this->plugin_locator->find_using_option('active_plugins'); |
|
| 66 | + foreach ($plugins as $path) { |
|
| 67 | + $active_plugins[$path] = $path; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | // This option contains all of the multisite plugins that have been activated. |
| 71 | - if ( is_multisite() ) { |
|
| 72 | - $plugins = $this->plugin_locator->find_using_option( 'active_sitewide_plugins', true ); |
|
| 73 | - foreach ( $plugins as $path ) { |
|
| 74 | - $active_plugins[ $path ] = $path; |
|
| 71 | + if (is_multisite()) { |
|
| 72 | + $plugins = $this->plugin_locator->find_using_option('active_sitewide_plugins', true); |
|
| 73 | + foreach ($plugins as $path) { |
|
| 74 | + $active_plugins[$path] = $path; |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // These actions contain plugins that are being activated/deactivated during this request. |
| 79 | - $plugins = $this->plugin_locator->find_using_request_action( array( 'activate', 'activate-selected', 'deactivate', 'deactivate-selected' ) ); |
|
| 80 | - foreach ( $plugins as $path ) { |
|
| 81 | - $active_plugins[ $path ] = $path; |
|
| 79 | + $plugins = $this->plugin_locator->find_using_request_action(array('activate', 'activate-selected', 'deactivate', 'deactivate-selected')); |
|
| 80 | + foreach ($plugins as $path) { |
|
| 81 | + $active_plugins[$path] = $path; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // When the current plugin isn't considered "active" there's a problem. |
@@ -89,22 +89,22 @@ discard block |
||
| 89 | 89 | // of causing a reset because the active plugins list has |
| 90 | 90 | // been changed since it was saved in the global. |
| 91 | 91 | $current_plugin = $this->plugin_locator->find_current_plugin(); |
| 92 | - if ( $record_unknown && ! in_array( $current_plugin, $active_plugins, true ) ) { |
|
| 93 | - $active_plugins[ $current_plugin ] = $current_plugin; |
|
| 92 | + if ($record_unknown && !in_array($current_plugin, $active_plugins, true)) { |
|
| 93 | + $active_plugins[$current_plugin] = $current_plugin; |
|
| 94 | 94 | $jetpack_autoloader_activating_plugins_paths[] = $current_plugin; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | // When deactivating plugins aren't desired we should entirely remove them from the active list. |
| 98 | - if ( ! $include_deactivating ) { |
|
| 98 | + if (!$include_deactivating) { |
|
| 99 | 99 | // These actions contain plugins that are being deactivated during this request. |
| 100 | - $plugins = $this->plugin_locator->find_using_request_action( array( 'deactivate', 'deactivate-selected' ) ); |
|
| 101 | - foreach ( $plugins as $path ) { |
|
| 102 | - unset( $active_plugins[ $path ] ); |
|
| 100 | + $plugins = $this->plugin_locator->find_using_request_action(array('deactivate', 'deactivate-selected')); |
|
| 101 | + foreach ($plugins as $path) { |
|
| 102 | + unset($active_plugins[$path]); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Transform the array so that we don't have to worry about the keys interacting with other array types later. |
| 107 | - return array_values( $active_plugins ); |
|
| 107 | + return array_values($active_plugins); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -113,13 +113,13 @@ discard block |
||
| 113 | 113 | * @return string[] |
| 114 | 114 | */ |
| 115 | 115 | public function get_cached_plugins() { |
| 116 | - $cached = get_transient( self::TRANSIENT_KEY ); |
|
| 117 | - if ( ! is_array( $cached ) || empty( $cached ) ) { |
|
| 116 | + $cached = get_transient(self::TRANSIENT_KEY); |
|
| 117 | + if (!is_array($cached) || empty($cached)) { |
|
| 118 | 118 | return array(); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // We need to expand the tokens to an absolute path for this webserver. |
| 122 | - return array_map( array( $this->path_processor, 'untokenize_path_constants' ), $cached ); |
|
| 122 | + return array_map(array($this->path_processor, 'untokenize_path_constants'), $cached); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -127,11 +127,11 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @param array $plugins The plugin list to save to the cache. |
| 129 | 129 | */ |
| 130 | - public function cache_plugins( $plugins ) { |
|
| 130 | + public function cache_plugins($plugins) { |
|
| 131 | 131 | // We store the paths in a tokenized form so that that webservers with different absolute paths don't break. |
| 132 | - $plugins = array_map( array( $this->path_processor, 'tokenize_path_constants' ), $plugins ); |
|
| 132 | + $plugins = array_map(array($this->path_processor, 'tokenize_path_constants'), $plugins); |
|
| 133 | 133 | |
| 134 | - set_transient( self::TRANSIENT_KEY, $plugins ); |
|
| 134 | + set_transient(self::TRANSIENT_KEY, $plugins); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @return bool True if the plugins have changed, otherwise false. |
| 145 | 145 | */ |
| 146 | - public function have_plugins_changed( $plugins ) { |
|
| 146 | + public function have_plugins_changed($plugins) { |
|
| 147 | 147 | global $jetpack_autoloader_cached_plugin_paths; |
| 148 | 148 | |
| 149 | - if ( $jetpack_autoloader_cached_plugin_paths !== $plugins ) { |
|
| 149 | + if ($jetpack_autoloader_cached_plugin_paths !== $plugins) { |
|
| 150 | 150 | $jetpack_autoloader_cached_plugin_paths = $plugins; |
| 151 | 151 | return true; |
| 152 | 152 | } |
@@ -7,70 +7,70 @@ |
||
| 7 | 7 | |
| 8 | 8 | namespace Automattic\Jetpack\Autoloader\jp526c9128fcc85a1cd942451999a66eb0; |
| 9 | 9 | |
| 10 | - // phpcs:ignore |
|
| 10 | + // phpcs:ignore |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * Allows the latest autoloader to register hooks that can be removed when the autoloader is reset. |
| 14 | 14 | */ |
| 15 | 15 | class Hook_Manager { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * An array containing all of the hooks that we've registered. |
|
| 19 | - * |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - private $registered_hooks; |
|
| 17 | + /** |
|
| 18 | + * An array containing all of the hooks that we've registered. |
|
| 19 | + * |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + private $registered_hooks; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * The constructor. |
|
| 26 | - */ |
|
| 27 | - public function __construct() { |
|
| 28 | - $this->registered_hooks = array(); |
|
| 29 | - } |
|
| 24 | + /** |
|
| 25 | + * The constructor. |
|
| 26 | + */ |
|
| 27 | + public function __construct() { |
|
| 28 | + $this->registered_hooks = array(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Adds an action to WordPress and registers it internally. |
|
| 33 | - * |
|
| 34 | - * @param string $tag The name of the action which is hooked. |
|
| 35 | - * @param callable $callable The function to call. |
|
| 36 | - * @param int $priority Used to specify the priority of the action. |
|
| 37 | - * @param int $accepted_args Used to specify the number of arguments the callable accepts. |
|
| 38 | - */ |
|
| 39 | - public function add_action( $tag, $callable, $priority = 10, $accepted_args = 1 ) { |
|
| 40 | - $this->registered_hooks[ $tag ][] = array( |
|
| 41 | - 'priority' => $priority, |
|
| 42 | - 'callable' => $callable, |
|
| 43 | - ); |
|
| 31 | + /** |
|
| 32 | + * Adds an action to WordPress and registers it internally. |
|
| 33 | + * |
|
| 34 | + * @param string $tag The name of the action which is hooked. |
|
| 35 | + * @param callable $callable The function to call. |
|
| 36 | + * @param int $priority Used to specify the priority of the action. |
|
| 37 | + * @param int $accepted_args Used to specify the number of arguments the callable accepts. |
|
| 38 | + */ |
|
| 39 | + public function add_action( $tag, $callable, $priority = 10, $accepted_args = 1 ) { |
|
| 40 | + $this->registered_hooks[ $tag ][] = array( |
|
| 41 | + 'priority' => $priority, |
|
| 42 | + 'callable' => $callable, |
|
| 43 | + ); |
|
| 44 | 44 | |
| 45 | - add_action( $tag, $callable, $priority, $accepted_args ); |
|
| 46 | - } |
|
| 45 | + add_action( $tag, $callable, $priority, $accepted_args ); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Adds a filter to WordPress and registers it internally. |
|
| 50 | - * |
|
| 51 | - * @param string $tag The name of the filter which is hooked. |
|
| 52 | - * @param callable $callable The function to call. |
|
| 53 | - * @param int $priority Used to specify the priority of the filter. |
|
| 54 | - * @param int $accepted_args Used to specify the number of arguments the callable accepts. |
|
| 55 | - */ |
|
| 56 | - public function add_filter( $tag, $callable, $priority = 10, $accepted_args = 1 ) { |
|
| 57 | - $this->registered_hooks[ $tag ][] = array( |
|
| 58 | - 'priority' => $priority, |
|
| 59 | - 'callable' => $callable, |
|
| 60 | - ); |
|
| 48 | + /** |
|
| 49 | + * Adds a filter to WordPress and registers it internally. |
|
| 50 | + * |
|
| 51 | + * @param string $tag The name of the filter which is hooked. |
|
| 52 | + * @param callable $callable The function to call. |
|
| 53 | + * @param int $priority Used to specify the priority of the filter. |
|
| 54 | + * @param int $accepted_args Used to specify the number of arguments the callable accepts. |
|
| 55 | + */ |
|
| 56 | + public function add_filter( $tag, $callable, $priority = 10, $accepted_args = 1 ) { |
|
| 57 | + $this->registered_hooks[ $tag ][] = array( |
|
| 58 | + 'priority' => $priority, |
|
| 59 | + 'callable' => $callable, |
|
| 60 | + ); |
|
| 61 | 61 | |
| 62 | - add_filter( $tag, $callable, $priority, $accepted_args ); |
|
| 63 | - } |
|
| 62 | + add_filter( $tag, $callable, $priority, $accepted_args ); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Removes all of the registered hooks. |
|
| 67 | - */ |
|
| 68 | - public function reset() { |
|
| 69 | - foreach ( $this->registered_hooks as $tag => $hooks ) { |
|
| 70 | - foreach ( $hooks as $hook ) { |
|
| 71 | - remove_filter( $tag, $hook['callable'], $hook['priority'] ); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - $this->registered_hooks = array(); |
|
| 75 | - } |
|
| 65 | + /** |
|
| 66 | + * Removes all of the registered hooks. |
|
| 67 | + */ |
|
| 68 | + public function reset() { |
|
| 69 | + foreach ( $this->registered_hooks as $tag => $hooks ) { |
|
| 70 | + foreach ( $hooks as $hook ) { |
|
| 71 | + remove_filter( $tag, $hook['callable'], $hook['priority'] ); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + $this->registered_hooks = array(); |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -28,13 +28,13 @@ discard block |
||
| 28 | 28 | * @param int $priority Used to specify the priority of the action. |
| 29 | 29 | * @param int $accepted_args Used to specify the number of arguments the callable accepts. |
| 30 | 30 | */ |
| 31 | - public function add_action( $tag, $callable, $priority = 10, $accepted_args = 1 ) { |
|
| 32 | - $this->registered_hooks[ $tag ][] = array( |
|
| 31 | + public function add_action($tag, $callable, $priority = 10, $accepted_args = 1) { |
|
| 32 | + $this->registered_hooks[$tag][] = array( |
|
| 33 | 33 | 'priority' => $priority, |
| 34 | 34 | 'callable' => $callable, |
| 35 | 35 | ); |
| 36 | 36 | |
| 37 | - add_action( $tag, $callable, $priority, $accepted_args ); |
|
| 37 | + add_action($tag, $callable, $priority, $accepted_args); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -45,22 +45,22 @@ discard block |
||
| 45 | 45 | * @param int $priority Used to specify the priority of the filter. |
| 46 | 46 | * @param int $accepted_args Used to specify the number of arguments the callable accepts. |
| 47 | 47 | */ |
| 48 | - public function add_filter( $tag, $callable, $priority = 10, $accepted_args = 1 ) { |
|
| 49 | - $this->registered_hooks[ $tag ][] = array( |
|
| 48 | + public function add_filter($tag, $callable, $priority = 10, $accepted_args = 1) { |
|
| 49 | + $this->registered_hooks[$tag][] = array( |
|
| 50 | 50 | 'priority' => $priority, |
| 51 | 51 | 'callable' => $callable, |
| 52 | 52 | ); |
| 53 | 53 | |
| 54 | - add_filter( $tag, $callable, $priority, $accepted_args ); |
|
| 54 | + add_filter($tag, $callable, $priority, $accepted_args); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * Removes all of the registered hooks. |
| 59 | 59 | */ |
| 60 | 60 | public function reset() { |
| 61 | - foreach ( $this->registered_hooks as $tag => $hooks ) { |
|
| 62 | - foreach ( $hooks as $hook ) { |
|
| 63 | - remove_filter( $tag, $hook['callable'], $hook['priority'] ); |
|
| 61 | + foreach ($this->registered_hooks as $tag => $hooks) { |
|
| 62 | + foreach ($hooks as $hook) { |
|
| 63 | + remove_filter($tag, $hook['callable'], $hook['priority']); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | $this->registered_hooks = array(); |
@@ -7,188 +7,188 @@ |
||
| 7 | 7 | |
| 8 | 8 | namespace Automattic\Jetpack\Autoloader\jp526c9128fcc85a1cd942451999a66eb0; |
| 9 | 9 | |
| 10 | - // phpcs:ignore |
|
| 10 | + // phpcs:ignore |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * This class handles dealing with paths for the autoloader. |
| 14 | 14 | */ |
| 15 | 15 | class Path_Processor { |
| 16 | - /** |
|
| 17 | - * Given a path this will replace any of the path constants with a token to represent it. |
|
| 18 | - * |
|
| 19 | - * @param string $path The path we want to process. |
|
| 20 | - * |
|
| 21 | - * @return string The tokenized path. |
|
| 22 | - */ |
|
| 23 | - public function tokenize_path_constants( $path ) { |
|
| 24 | - $path = wp_normalize_path( $path ); |
|
| 25 | - |
|
| 26 | - $constants = $this->get_normalized_constants(); |
|
| 27 | - foreach ( $constants as $constant => $constant_path ) { |
|
| 28 | - $len = strlen( $constant_path ); |
|
| 29 | - if ( substr( $path, 0, $len ) !== $constant_path ) { |
|
| 30 | - continue; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - return substr_replace( $path, '{{' . $constant . '}}', 0, $len ); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - return $path; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Given a path this will replace any of the path constant tokens with the expanded path. |
|
| 41 | - * |
|
| 42 | - * @param string $tokenized_path The path we want to process. |
|
| 43 | - * |
|
| 44 | - * @return string The expanded path. |
|
| 45 | - */ |
|
| 46 | - public function untokenize_path_constants( $tokenized_path ) { |
|
| 47 | - $tokenized_path = wp_normalize_path( $tokenized_path ); |
|
| 48 | - |
|
| 49 | - $constants = $this->get_normalized_constants(); |
|
| 50 | - foreach ( $constants as $constant => $constant_path ) { |
|
| 51 | - $constant = '{{' . $constant . '}}'; |
|
| 52 | - |
|
| 53 | - $len = strlen( $constant ); |
|
| 54 | - if ( substr( $tokenized_path, 0, $len ) !== $constant ) { |
|
| 55 | - continue; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - return $this->get_real_path( substr_replace( $tokenized_path, $constant_path, 0, $len ) ); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - return $tokenized_path; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Given a file and an array of places it might be, this will find the absolute path and return it. |
|
| 66 | - * |
|
| 67 | - * @param string $file The plugin or theme file to resolve. |
|
| 68 | - * @param array $directories_to_check The directories we should check for the file if it isn't an absolute path. |
|
| 69 | - * |
|
| 70 | - * @return string|false Returns the absolute path to the directory, otherwise false. |
|
| 71 | - */ |
|
| 72 | - public function find_directory_with_autoloader( $file, $directories_to_check ) { |
|
| 73 | - $file = wp_normalize_path( $file ); |
|
| 74 | - |
|
| 75 | - if ( ! $this->is_absolute_path( $file ) ) { |
|
| 76 | - $file = $this->find_absolute_plugin_path( $file, $directories_to_check ); |
|
| 77 | - if ( ! isset( $file ) ) { |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - // We need the real path for consistency with __DIR__ paths. |
|
| 83 | - $file = $this->get_real_path( $file ); |
|
| 84 | - |
|
| 85 | - // phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 86 | - $directory = @is_file( $file ) ? dirname( $file ) : $file; |
|
| 87 | - if ( ! @is_file( $directory . '/vendor/composer/jetpack_autoload_classmap.php' ) ) { |
|
| 88 | - return false; |
|
| 89 | - } |
|
| 90 | - // phpcs:enable WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 91 | - |
|
| 92 | - return $directory; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Fetches an array of normalized paths keyed by the constant they came from. |
|
| 97 | - * |
|
| 98 | - * @return string[] The normalized paths keyed by the constant. |
|
| 99 | - */ |
|
| 100 | - private function get_normalized_constants() { |
|
| 101 | - $raw_constants = array( |
|
| 102 | - // Order the constants from most-specific to least-specific. |
|
| 103 | - 'WP_PLUGIN_DIR', |
|
| 104 | - 'WPMU_PLUGIN_DIR', |
|
| 105 | - 'WP_CONTENT_DIR', |
|
| 106 | - 'ABSPATH', |
|
| 107 | - ); |
|
| 108 | - |
|
| 109 | - $constants = array(); |
|
| 110 | - foreach ( $raw_constants as $raw ) { |
|
| 111 | - if ( ! defined( $raw ) ) { |
|
| 112 | - continue; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $path = wp_normalize_path( constant( $raw ) ); |
|
| 116 | - if ( isset( $path ) ) { |
|
| 117 | - $constants[ $raw ] = $path; |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - return $constants; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Indicates whether or not a path is absolute. |
|
| 126 | - * |
|
| 127 | - * @param string $path The path to check. |
|
| 128 | - * |
|
| 129 | - * @return bool True if the path is absolute, otherwise false. |
|
| 130 | - */ |
|
| 131 | - private function is_absolute_path( $path ) { |
|
| 132 | - if ( 0 === strlen( $path ) || '.' === $path[0] ) { |
|
| 133 | - return false; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // Absolute paths on Windows may begin with a drive letter. |
|
| 137 | - if ( preg_match( '/^[a-zA-Z]:[\/\\\\]/', $path ) ) { |
|
| 138 | - return true; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - // A path starting with / or \ is absolute; anything else is relative. |
|
| 142 | - return ( '/' === $path[0] || '\\' === $path[0] ); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Given a file and a list of directories to check, this method will try to figure out |
|
| 147 | - * the absolute path to the file in question. |
|
| 148 | - * |
|
| 149 | - * @param string $normalized_path The normalized path to the plugin or theme file to resolve. |
|
| 150 | - * @param array $directories_to_check The directories we should check for the file if it isn't an absolute path. |
|
| 151 | - * |
|
| 152 | - * @return string|null The absolute path to the plugin file, otherwise null. |
|
| 153 | - */ |
|
| 154 | - private function find_absolute_plugin_path( $normalized_path, $directories_to_check ) { |
|
| 155 | - // We're only able to find the absolute path for plugin/theme PHP files. |
|
| 156 | - if ( ! is_string( $normalized_path ) || '.php' !== substr( $normalized_path, -4 ) ) { |
|
| 157 | - return null; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - foreach ( $directories_to_check as $directory ) { |
|
| 161 | - $normalized_check = wp_normalize_path( trailingslashit( $directory ) ) . $normalized_path; |
|
| 162 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 163 | - if ( @is_file( $normalized_check ) ) { |
|
| 164 | - return $normalized_check; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return null; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Given a path this will figure out the real path that we should be using. |
|
| 173 | - * |
|
| 174 | - * @param string $path The path to resolve. |
|
| 175 | - * |
|
| 176 | - * @return string The resolved path. |
|
| 177 | - */ |
|
| 178 | - private function get_real_path( $path ) { |
|
| 179 | - // We want to resolve symbolic links for consistency with __DIR__ paths. |
|
| 180 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 181 | - $real_path = @realpath( $path ); |
|
| 182 | - if ( false === $real_path ) { |
|
| 183 | - // Let the autoloader deal with paths that don't exist. |
|
| 184 | - $real_path = $path; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - // Using realpath will make it platform-specific so we must normalize it after. |
|
| 188 | - if ( $path !== $real_path ) { |
|
| 189 | - $real_path = wp_normalize_path( $real_path ); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - return $real_path; |
|
| 193 | - } |
|
| 16 | + /** |
|
| 17 | + * Given a path this will replace any of the path constants with a token to represent it. |
|
| 18 | + * |
|
| 19 | + * @param string $path The path we want to process. |
|
| 20 | + * |
|
| 21 | + * @return string The tokenized path. |
|
| 22 | + */ |
|
| 23 | + public function tokenize_path_constants( $path ) { |
|
| 24 | + $path = wp_normalize_path( $path ); |
|
| 25 | + |
|
| 26 | + $constants = $this->get_normalized_constants(); |
|
| 27 | + foreach ( $constants as $constant => $constant_path ) { |
|
| 28 | + $len = strlen( $constant_path ); |
|
| 29 | + if ( substr( $path, 0, $len ) !== $constant_path ) { |
|
| 30 | + continue; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + return substr_replace( $path, '{{' . $constant . '}}', 0, $len ); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + return $path; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Given a path this will replace any of the path constant tokens with the expanded path. |
|
| 41 | + * |
|
| 42 | + * @param string $tokenized_path The path we want to process. |
|
| 43 | + * |
|
| 44 | + * @return string The expanded path. |
|
| 45 | + */ |
|
| 46 | + public function untokenize_path_constants( $tokenized_path ) { |
|
| 47 | + $tokenized_path = wp_normalize_path( $tokenized_path ); |
|
| 48 | + |
|
| 49 | + $constants = $this->get_normalized_constants(); |
|
| 50 | + foreach ( $constants as $constant => $constant_path ) { |
|
| 51 | + $constant = '{{' . $constant . '}}'; |
|
| 52 | + |
|
| 53 | + $len = strlen( $constant ); |
|
| 54 | + if ( substr( $tokenized_path, 0, $len ) !== $constant ) { |
|
| 55 | + continue; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + return $this->get_real_path( substr_replace( $tokenized_path, $constant_path, 0, $len ) ); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + return $tokenized_path; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Given a file and an array of places it might be, this will find the absolute path and return it. |
|
| 66 | + * |
|
| 67 | + * @param string $file The plugin or theme file to resolve. |
|
| 68 | + * @param array $directories_to_check The directories we should check for the file if it isn't an absolute path. |
|
| 69 | + * |
|
| 70 | + * @return string|false Returns the absolute path to the directory, otherwise false. |
|
| 71 | + */ |
|
| 72 | + public function find_directory_with_autoloader( $file, $directories_to_check ) { |
|
| 73 | + $file = wp_normalize_path( $file ); |
|
| 74 | + |
|
| 75 | + if ( ! $this->is_absolute_path( $file ) ) { |
|
| 76 | + $file = $this->find_absolute_plugin_path( $file, $directories_to_check ); |
|
| 77 | + if ( ! isset( $file ) ) { |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + // We need the real path for consistency with __DIR__ paths. |
|
| 83 | + $file = $this->get_real_path( $file ); |
|
| 84 | + |
|
| 85 | + // phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 86 | + $directory = @is_file( $file ) ? dirname( $file ) : $file; |
|
| 87 | + if ( ! @is_file( $directory . '/vendor/composer/jetpack_autoload_classmap.php' ) ) { |
|
| 88 | + return false; |
|
| 89 | + } |
|
| 90 | + // phpcs:enable WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 91 | + |
|
| 92 | + return $directory; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Fetches an array of normalized paths keyed by the constant they came from. |
|
| 97 | + * |
|
| 98 | + * @return string[] The normalized paths keyed by the constant. |
|
| 99 | + */ |
|
| 100 | + private function get_normalized_constants() { |
|
| 101 | + $raw_constants = array( |
|
| 102 | + // Order the constants from most-specific to least-specific. |
|
| 103 | + 'WP_PLUGIN_DIR', |
|
| 104 | + 'WPMU_PLUGIN_DIR', |
|
| 105 | + 'WP_CONTENT_DIR', |
|
| 106 | + 'ABSPATH', |
|
| 107 | + ); |
|
| 108 | + |
|
| 109 | + $constants = array(); |
|
| 110 | + foreach ( $raw_constants as $raw ) { |
|
| 111 | + if ( ! defined( $raw ) ) { |
|
| 112 | + continue; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $path = wp_normalize_path( constant( $raw ) ); |
|
| 116 | + if ( isset( $path ) ) { |
|
| 117 | + $constants[ $raw ] = $path; |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + return $constants; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Indicates whether or not a path is absolute. |
|
| 126 | + * |
|
| 127 | + * @param string $path The path to check. |
|
| 128 | + * |
|
| 129 | + * @return bool True if the path is absolute, otherwise false. |
|
| 130 | + */ |
|
| 131 | + private function is_absolute_path( $path ) { |
|
| 132 | + if ( 0 === strlen( $path ) || '.' === $path[0] ) { |
|
| 133 | + return false; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // Absolute paths on Windows may begin with a drive letter. |
|
| 137 | + if ( preg_match( '/^[a-zA-Z]:[\/\\\\]/', $path ) ) { |
|
| 138 | + return true; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + // A path starting with / or \ is absolute; anything else is relative. |
|
| 142 | + return ( '/' === $path[0] || '\\' === $path[0] ); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Given a file and a list of directories to check, this method will try to figure out |
|
| 147 | + * the absolute path to the file in question. |
|
| 148 | + * |
|
| 149 | + * @param string $normalized_path The normalized path to the plugin or theme file to resolve. |
|
| 150 | + * @param array $directories_to_check The directories we should check for the file if it isn't an absolute path. |
|
| 151 | + * |
|
| 152 | + * @return string|null The absolute path to the plugin file, otherwise null. |
|
| 153 | + */ |
|
| 154 | + private function find_absolute_plugin_path( $normalized_path, $directories_to_check ) { |
|
| 155 | + // We're only able to find the absolute path for plugin/theme PHP files. |
|
| 156 | + if ( ! is_string( $normalized_path ) || '.php' !== substr( $normalized_path, -4 ) ) { |
|
| 157 | + return null; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + foreach ( $directories_to_check as $directory ) { |
|
| 161 | + $normalized_check = wp_normalize_path( trailingslashit( $directory ) ) . $normalized_path; |
|
| 162 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 163 | + if ( @is_file( $normalized_check ) ) { |
|
| 164 | + return $normalized_check; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + return null; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Given a path this will figure out the real path that we should be using. |
|
| 173 | + * |
|
| 174 | + * @param string $path The path to resolve. |
|
| 175 | + * |
|
| 176 | + * @return string The resolved path. |
|
| 177 | + */ |
|
| 178 | + private function get_real_path( $path ) { |
|
| 179 | + // We want to resolve symbolic links for consistency with __DIR__ paths. |
|
| 180 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 181 | + $real_path = @realpath( $path ); |
|
| 182 | + if ( false === $real_path ) { |
|
| 183 | + // Let the autoloader deal with paths that don't exist. |
|
| 184 | + $real_path = $path; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + // Using realpath will make it platform-specific so we must normalize it after. |
|
| 188 | + if ( $path !== $real_path ) { |
|
| 189 | + $real_path = wp_normalize_path( $real_path ); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + return $real_path; |
|
| 193 | + } |
|
| 194 | 194 | } |
@@ -12,17 +12,17 @@ discard block |
||
| 12 | 12 | * |
| 13 | 13 | * @return string The tokenized path. |
| 14 | 14 | */ |
| 15 | - public function tokenize_path_constants( $path ) { |
|
| 16 | - $path = wp_normalize_path( $path ); |
|
| 15 | + public function tokenize_path_constants($path) { |
|
| 16 | + $path = wp_normalize_path($path); |
|
| 17 | 17 | |
| 18 | 18 | $constants = $this->get_normalized_constants(); |
| 19 | - foreach ( $constants as $constant => $constant_path ) { |
|
| 20 | - $len = strlen( $constant_path ); |
|
| 21 | - if ( substr( $path, 0, $len ) !== $constant_path ) { |
|
| 19 | + foreach ($constants as $constant => $constant_path) { |
|
| 20 | + $len = strlen($constant_path); |
|
| 21 | + if (substr($path, 0, $len) !== $constant_path) { |
|
| 22 | 22 | continue; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - return substr_replace( $path, '{{' . $constant . '}}', 0, $len ); |
|
| 25 | + return substr_replace($path, '{{' . $constant . '}}', 0, $len); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | return $path; |
@@ -35,19 +35,19 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @return string The expanded path. |
| 37 | 37 | */ |
| 38 | - public function untokenize_path_constants( $tokenized_path ) { |
|
| 39 | - $tokenized_path = wp_normalize_path( $tokenized_path ); |
|
| 38 | + public function untokenize_path_constants($tokenized_path) { |
|
| 39 | + $tokenized_path = wp_normalize_path($tokenized_path); |
|
| 40 | 40 | |
| 41 | 41 | $constants = $this->get_normalized_constants(); |
| 42 | - foreach ( $constants as $constant => $constant_path ) { |
|
| 42 | + foreach ($constants as $constant => $constant_path) { |
|
| 43 | 43 | $constant = '{{' . $constant . '}}'; |
| 44 | 44 | |
| 45 | - $len = strlen( $constant ); |
|
| 46 | - if ( substr( $tokenized_path, 0, $len ) !== $constant ) { |
|
| 45 | + $len = strlen($constant); |
|
| 46 | + if (substr($tokenized_path, 0, $len) !== $constant) { |
|
| 47 | 47 | continue; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - return $this->get_real_path( substr_replace( $tokenized_path, $constant_path, 0, $len ) ); |
|
| 50 | + return $this->get_real_path(substr_replace($tokenized_path, $constant_path, 0, $len)); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | return $tokenized_path; |
@@ -61,22 +61,22 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @return string|false Returns the absolute path to the directory, otherwise false. |
| 63 | 63 | */ |
| 64 | - public function find_directory_with_autoloader( $file, $directories_to_check ) { |
|
| 65 | - $file = wp_normalize_path( $file ); |
|
| 64 | + public function find_directory_with_autoloader($file, $directories_to_check) { |
|
| 65 | + $file = wp_normalize_path($file); |
|
| 66 | 66 | |
| 67 | - if ( ! $this->is_absolute_path( $file ) ) { |
|
| 68 | - $file = $this->find_absolute_plugin_path( $file, $directories_to_check ); |
|
| 69 | - if ( ! isset( $file ) ) { |
|
| 67 | + if (!$this->is_absolute_path($file)) { |
|
| 68 | + $file = $this->find_absolute_plugin_path($file, $directories_to_check); |
|
| 69 | + if (!isset($file)) { |
|
| 70 | 70 | return false; |
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // We need the real path for consistency with __DIR__ paths. |
| 75 | - $file = $this->get_real_path( $file ); |
|
| 75 | + $file = $this->get_real_path($file); |
|
| 76 | 76 | |
| 77 | 77 | // phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged |
| 78 | - $directory = @is_file( $file ) ? dirname( $file ) : $file; |
|
| 79 | - if ( ! @is_file( $directory . '/vendor/composer/jetpack_autoload_classmap.php' ) ) { |
|
| 78 | + $directory = @is_file($file) ? dirname($file) : $file; |
|
| 79 | + if (!@is_file($directory . '/vendor/composer/jetpack_autoload_classmap.php')) { |
|
| 80 | 80 | return false; |
| 81 | 81 | } |
| 82 | 82 | // phpcs:enable WordPress.PHP.NoSilencedErrors.Discouraged |
@@ -99,14 +99,14 @@ discard block |
||
| 99 | 99 | ); |
| 100 | 100 | |
| 101 | 101 | $constants = array(); |
| 102 | - foreach ( $raw_constants as $raw ) { |
|
| 103 | - if ( ! defined( $raw ) ) { |
|
| 102 | + foreach ($raw_constants as $raw) { |
|
| 103 | + if (!defined($raw)) { |
|
| 104 | 104 | continue; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - $path = wp_normalize_path( constant( $raw ) ); |
|
| 108 | - if ( isset( $path ) ) { |
|
| 109 | - $constants[ $raw ] = $path; |
|
| 107 | + $path = wp_normalize_path(constant($raw)); |
|
| 108 | + if (isset($path)) { |
|
| 109 | + $constants[$raw] = $path; |
|
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | |
@@ -120,18 +120,18 @@ discard block |
||
| 120 | 120 | * |
| 121 | 121 | * @return bool True if the path is absolute, otherwise false. |
| 122 | 122 | */ |
| 123 | - private function is_absolute_path( $path ) { |
|
| 124 | - if ( 0 === strlen( $path ) || '.' === $path[0] ) { |
|
| 123 | + private function is_absolute_path($path) { |
|
| 124 | + if (0 === strlen($path) || '.' === $path[0]) { |
|
| 125 | 125 | return false; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // Absolute paths on Windows may begin with a drive letter. |
| 129 | - if ( preg_match( '/^[a-zA-Z]:[\/\\\\]/', $path ) ) { |
|
| 129 | + if (preg_match('/^[a-zA-Z]:[\/\\\\]/', $path)) { |
|
| 130 | 130 | return true; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | // A path starting with / or \ is absolute; anything else is relative. |
| 134 | - return ( '/' === $path[0] || '\\' === $path[0] ); |
|
| 134 | + return ('/' === $path[0] || '\\' === $path[0]); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -143,16 +143,16 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @return string|null The absolute path to the plugin file, otherwise null. |
| 145 | 145 | */ |
| 146 | - private function find_absolute_plugin_path( $normalized_path, $directories_to_check ) { |
|
| 146 | + private function find_absolute_plugin_path($normalized_path, $directories_to_check) { |
|
| 147 | 147 | // We're only able to find the absolute path for plugin/theme PHP files. |
| 148 | - if ( ! is_string( $normalized_path ) || '.php' !== substr( $normalized_path, -4 ) ) { |
|
| 148 | + if (!is_string($normalized_path) || '.php' !== substr($normalized_path, -4)) { |
|
| 149 | 149 | return null; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - foreach ( $directories_to_check as $directory ) { |
|
| 153 | - $normalized_check = wp_normalize_path( trailingslashit( $directory ) ) . $normalized_path; |
|
| 152 | + foreach ($directories_to_check as $directory) { |
|
| 153 | + $normalized_check = wp_normalize_path(trailingslashit($directory)) . $normalized_path; |
|
| 154 | 154 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
| 155 | - if ( @is_file( $normalized_check ) ) { |
|
| 155 | + if (@is_file($normalized_check)) { |
|
| 156 | 156 | return $normalized_check; |
| 157 | 157 | } |
| 158 | 158 | } |
@@ -167,18 +167,18 @@ discard block |
||
| 167 | 167 | * |
| 168 | 168 | * @return string The resolved path. |
| 169 | 169 | */ |
| 170 | - private function get_real_path( $path ) { |
|
| 170 | + private function get_real_path($path) { |
|
| 171 | 171 | // We want to resolve symbolic links for consistency with __DIR__ paths. |
| 172 | 172 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
| 173 | - $real_path = @realpath( $path ); |
|
| 174 | - if ( false === $real_path ) { |
|
| 173 | + $real_path = @realpath($path); |
|
| 174 | + if (false === $real_path) { |
|
| 175 | 175 | // Let the autoloader deal with paths that don't exist. |
| 176 | 176 | $real_path = $path; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | // Using realpath will make it platform-specific so we must normalize it after. |
| 180 | - if ( $path !== $real_path ) { |
|
| 181 | - $real_path = wp_normalize_path( $real_path ); |
|
| 180 | + if ($path !== $real_path) { |
|
| 181 | + $real_path = wp_normalize_path($real_path); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | return $real_path; |
@@ -7,63 +7,63 @@ |
||
| 7 | 7 | |
| 8 | 8 | namespace Automattic\Jetpack\Autoloader\jp526c9128fcc85a1cd942451999a66eb0; |
| 9 | 9 | |
| 10 | - // phpcs:ignore |
|
| 10 | + // phpcs:ignore |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * Used to select package versions. |
| 14 | 14 | */ |
| 15 | 15 | class Version_Selector { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Checks whether the selected package version should be updated. Composer development |
|
| 19 | - * package versions ('9999999-dev' or versions that start with 'dev-') are favored |
|
| 20 | - * when the JETPACK_AUTOLOAD_DEV constant is set to true. |
|
| 21 | - * |
|
| 22 | - * @param String $selected_version The currently selected package version. |
|
| 23 | - * @param String $compare_version The package version that is being evaluated to |
|
| 24 | - * determine if the version needs to be updated. |
|
| 25 | - * |
|
| 26 | - * @return bool Returns true if the selected package version should be updated, |
|
| 27 | - * else false. |
|
| 28 | - */ |
|
| 29 | - public function is_version_update_required( $selected_version, $compare_version ) { |
|
| 30 | - $use_dev_versions = defined( 'JETPACK_AUTOLOAD_DEV' ) && JETPACK_AUTOLOAD_DEV; |
|
| 17 | + /** |
|
| 18 | + * Checks whether the selected package version should be updated. Composer development |
|
| 19 | + * package versions ('9999999-dev' or versions that start with 'dev-') are favored |
|
| 20 | + * when the JETPACK_AUTOLOAD_DEV constant is set to true. |
|
| 21 | + * |
|
| 22 | + * @param String $selected_version The currently selected package version. |
|
| 23 | + * @param String $compare_version The package version that is being evaluated to |
|
| 24 | + * determine if the version needs to be updated. |
|
| 25 | + * |
|
| 26 | + * @return bool Returns true if the selected package version should be updated, |
|
| 27 | + * else false. |
|
| 28 | + */ |
|
| 29 | + public function is_version_update_required( $selected_version, $compare_version ) { |
|
| 30 | + $use_dev_versions = defined( 'JETPACK_AUTOLOAD_DEV' ) && JETPACK_AUTOLOAD_DEV; |
|
| 31 | 31 | |
| 32 | - if ( is_null( $selected_version ) ) { |
|
| 33 | - return true; |
|
| 34 | - } |
|
| 32 | + if ( is_null( $selected_version ) ) { |
|
| 33 | + return true; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - if ( $use_dev_versions && $this->is_dev_version( $selected_version ) ) { |
|
| 37 | - return false; |
|
| 38 | - } |
|
| 36 | + if ( $use_dev_versions && $this->is_dev_version( $selected_version ) ) { |
|
| 37 | + return false; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - if ( $this->is_dev_version( $compare_version ) ) { |
|
| 41 | - if ( $use_dev_versions ) { |
|
| 42 | - return true; |
|
| 43 | - } else { |
|
| 44 | - return false; |
|
| 45 | - } |
|
| 46 | - } |
|
| 40 | + if ( $this->is_dev_version( $compare_version ) ) { |
|
| 41 | + if ( $use_dev_versions ) { |
|
| 42 | + return true; |
|
| 43 | + } else { |
|
| 44 | + return false; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - if ( version_compare( $selected_version, $compare_version, '<' ) ) { |
|
| 49 | - return true; |
|
| 50 | - } |
|
| 48 | + if ( version_compare( $selected_version, $compare_version, '<' ) ) { |
|
| 49 | + return true; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - return false; |
|
| 53 | - } |
|
| 52 | + return false; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Checks whether the given package version is a development version. |
|
| 57 | - * |
|
| 58 | - * @param String $version The package version. |
|
| 59 | - * |
|
| 60 | - * @return bool True if the version is a dev version, else false. |
|
| 61 | - */ |
|
| 62 | - public function is_dev_version( $version ) { |
|
| 63 | - if ( 'dev-' === substr( $version, 0, 4 ) || '9999999-dev' === $version ) { |
|
| 64 | - return true; |
|
| 65 | - } |
|
| 55 | + /** |
|
| 56 | + * Checks whether the given package version is a development version. |
|
| 57 | + * |
|
| 58 | + * @param String $version The package version. |
|
| 59 | + * |
|
| 60 | + * @return bool True if the version is a dev version, else false. |
|
| 61 | + */ |
|
| 62 | + public function is_dev_version( $version ) { |
|
| 63 | + if ( 'dev-' === substr( $version, 0, 4 ) || '9999999-dev' === $version ) { |
|
| 64 | + return true; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - return false; |
|
| 68 | - } |
|
| 67 | + return false; |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -18,26 +18,26 @@ discard block |
||
| 18 | 18 | * @return bool Returns true if the selected package version should be updated, |
| 19 | 19 | * else false. |
| 20 | 20 | */ |
| 21 | - public function is_version_update_required( $selected_version, $compare_version ) { |
|
| 22 | - $use_dev_versions = defined( 'JETPACK_AUTOLOAD_DEV' ) && JETPACK_AUTOLOAD_DEV; |
|
| 21 | + public function is_version_update_required($selected_version, $compare_version) { |
|
| 22 | + $use_dev_versions = defined('JETPACK_AUTOLOAD_DEV') && JETPACK_AUTOLOAD_DEV; |
|
| 23 | 23 | |
| 24 | - if ( is_null( $selected_version ) ) { |
|
| 24 | + if (is_null($selected_version)) { |
|
| 25 | 25 | return true; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - if ( $use_dev_versions && $this->is_dev_version( $selected_version ) ) { |
|
| 28 | + if ($use_dev_versions && $this->is_dev_version($selected_version)) { |
|
| 29 | 29 | return false; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - if ( $this->is_dev_version( $compare_version ) ) { |
|
| 33 | - if ( $use_dev_versions ) { |
|
| 32 | + if ($this->is_dev_version($compare_version)) { |
|
| 33 | + if ($use_dev_versions) { |
|
| 34 | 34 | return true; |
| 35 | 35 | } else { |
| 36 | 36 | return false; |
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - if ( version_compare( $selected_version, $compare_version, '<' ) ) { |
|
| 40 | + if (version_compare($selected_version, $compare_version, '<')) { |
|
| 41 | 41 | return true; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @return bool True if the version is a dev version, else false. |
| 53 | 53 | */ |
| 54 | - public function is_dev_version( $version ) { |
|
| 55 | - if ( 'dev-' === substr( $version, 0, 4 ) || '9999999-dev' === $version ) { |
|
| 54 | + public function is_dev_version($version) { |
|
| 55 | + if ('dev-' === substr($version, 0, 4) || '9999999-dev' === $version) { |
|
| 56 | 56 | return true; |
| 57 | 57 | } |
| 58 | 58 | |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | namespace Automattic\Jetpack\Autoloader\jp526c9128fcc85a1cd942451999a66eb0; |
| 9 | 9 | |
| 10 | - // phpcs:ignore |
|
| 10 | + // phpcs:ignore |
|
| 11 | 11 | |
| 12 | 12 | use Automattic\Jetpack\Autoloader\AutoloadGenerator; |
| 13 | 13 | |
@@ -16,75 +16,75 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | class Autoloader_Locator { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The object for comparing autoloader versions. |
|
| 21 | - * |
|
| 22 | - * @var Version_Selector |
|
| 23 | - */ |
|
| 24 | - private $version_selector; |
|
| 19 | + /** |
|
| 20 | + * The object for comparing autoloader versions. |
|
| 21 | + * |
|
| 22 | + * @var Version_Selector |
|
| 23 | + */ |
|
| 24 | + private $version_selector; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * The constructor. |
|
| 28 | - * |
|
| 29 | - * @param Version_Selector $version_selector The version selector object. |
|
| 30 | - */ |
|
| 31 | - public function __construct( $version_selector ) { |
|
| 32 | - $this->version_selector = $version_selector; |
|
| 33 | - } |
|
| 26 | + /** |
|
| 27 | + * The constructor. |
|
| 28 | + * |
|
| 29 | + * @param Version_Selector $version_selector The version selector object. |
|
| 30 | + */ |
|
| 31 | + public function __construct( $version_selector ) { |
|
| 32 | + $this->version_selector = $version_selector; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Finds the path to the plugin with the latest autoloader. |
|
| 37 | - * |
|
| 38 | - * @param array $plugin_paths An array of plugin paths. |
|
| 39 | - * @param string $latest_version The latest version reference. |
|
| 40 | - * |
|
| 41 | - * @return string|null |
|
| 42 | - */ |
|
| 43 | - public function find_latest_autoloader( $plugin_paths, &$latest_version ) { |
|
| 44 | - $latest_plugin = null; |
|
| 35 | + /** |
|
| 36 | + * Finds the path to the plugin with the latest autoloader. |
|
| 37 | + * |
|
| 38 | + * @param array $plugin_paths An array of plugin paths. |
|
| 39 | + * @param string $latest_version The latest version reference. |
|
| 40 | + * |
|
| 41 | + * @return string|null |
|
| 42 | + */ |
|
| 43 | + public function find_latest_autoloader( $plugin_paths, &$latest_version ) { |
|
| 44 | + $latest_plugin = null; |
|
| 45 | 45 | |
| 46 | - foreach ( $plugin_paths as $plugin_path ) { |
|
| 47 | - $version = $this->get_autoloader_version( $plugin_path ); |
|
| 48 | - if ( ! $this->version_selector->is_version_update_required( $latest_version, $version ) ) { |
|
| 49 | - continue; |
|
| 50 | - } |
|
| 46 | + foreach ( $plugin_paths as $plugin_path ) { |
|
| 47 | + $version = $this->get_autoloader_version( $plugin_path ); |
|
| 48 | + if ( ! $this->version_selector->is_version_update_required( $latest_version, $version ) ) { |
|
| 49 | + continue; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - $latest_version = $version; |
|
| 53 | - $latest_plugin = $plugin_path; |
|
| 54 | - } |
|
| 52 | + $latest_version = $version; |
|
| 53 | + $latest_plugin = $plugin_path; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return $latest_plugin; |
|
| 57 | - } |
|
| 56 | + return $latest_plugin; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Gets the path to the autoloader. |
|
| 61 | - * |
|
| 62 | - * @param string $plugin_path The path to the plugin. |
|
| 63 | - * |
|
| 64 | - * @return string |
|
| 65 | - */ |
|
| 66 | - public function get_autoloader_path( $plugin_path ) { |
|
| 67 | - return trailingslashit( $plugin_path ) . 'vendor/autoload_packages.php'; |
|
| 68 | - } |
|
| 59 | + /** |
|
| 60 | + * Gets the path to the autoloader. |
|
| 61 | + * |
|
| 62 | + * @param string $plugin_path The path to the plugin. |
|
| 63 | + * |
|
| 64 | + * @return string |
|
| 65 | + */ |
|
| 66 | + public function get_autoloader_path( $plugin_path ) { |
|
| 67 | + return trailingslashit( $plugin_path ) . 'vendor/autoload_packages.php'; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Gets the version for the autoloader. |
|
| 72 | - * |
|
| 73 | - * @param string $plugin_path The path to the plugin. |
|
| 74 | - * |
|
| 75 | - * @return string|null |
|
| 76 | - */ |
|
| 77 | - public function get_autoloader_version( $plugin_path ) { |
|
| 78 | - $classmap = trailingslashit( $plugin_path ) . 'vendor/composer/jetpack_autoload_classmap.php'; |
|
| 79 | - if ( ! file_exists( $classmap ) ) { |
|
| 80 | - return null; |
|
| 81 | - } |
|
| 70 | + /** |
|
| 71 | + * Gets the version for the autoloader. |
|
| 72 | + * |
|
| 73 | + * @param string $plugin_path The path to the plugin. |
|
| 74 | + * |
|
| 75 | + * @return string|null |
|
| 76 | + */ |
|
| 77 | + public function get_autoloader_version( $plugin_path ) { |
|
| 78 | + $classmap = trailingslashit( $plugin_path ) . 'vendor/composer/jetpack_autoload_classmap.php'; |
|
| 79 | + if ( ! file_exists( $classmap ) ) { |
|
| 80 | + return null; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - $classmap = require $classmap; |
|
| 84 | - if ( isset( $classmap[ AutoloadGenerator::class ] ) ) { |
|
| 85 | - return $classmap[ AutoloadGenerator::class ]['version']; |
|
| 86 | - } |
|
| 83 | + $classmap = require $classmap; |
|
| 84 | + if ( isset( $classmap[ AutoloadGenerator::class ] ) ) { |
|
| 85 | + return $classmap[ AutoloadGenerator::class ]['version']; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - return null; |
|
| 89 | - } |
|
| 88 | + return null; |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @param Version_Selector $version_selector The version selector object. |
| 22 | 22 | */ |
| 23 | - public function __construct( $version_selector ) { |
|
| 23 | + public function __construct($version_selector) { |
|
| 24 | 24 | $this->version_selector = $version_selector; |
| 25 | 25 | } |
| 26 | 26 | |
@@ -32,12 +32,12 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @return string|null |
| 34 | 34 | */ |
| 35 | - public function find_latest_autoloader( $plugin_paths, &$latest_version ) { |
|
| 35 | + public function find_latest_autoloader($plugin_paths, &$latest_version) { |
|
| 36 | 36 | $latest_plugin = null; |
| 37 | 37 | |
| 38 | - foreach ( $plugin_paths as $plugin_path ) { |
|
| 39 | - $version = $this->get_autoloader_version( $plugin_path ); |
|
| 40 | - if ( ! $this->version_selector->is_version_update_required( $latest_version, $version ) ) { |
|
| 38 | + foreach ($plugin_paths as $plugin_path) { |
|
| 39 | + $version = $this->get_autoloader_version($plugin_path); |
|
| 40 | + if (!$this->version_selector->is_version_update_required($latest_version, $version)) { |
|
| 41 | 41 | continue; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @return string |
| 57 | 57 | */ |
| 58 | - public function get_autoloader_path( $plugin_path ) { |
|
| 59 | - return trailingslashit( $plugin_path ) . 'vendor/autoload_packages.php'; |
|
| 58 | + public function get_autoloader_path($plugin_path) { |
|
| 59 | + return trailingslashit($plugin_path) . 'vendor/autoload_packages.php'; |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -66,15 +66,15 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @return string|null |
| 68 | 68 | */ |
| 69 | - public function get_autoloader_version( $plugin_path ) { |
|
| 70 | - $classmap = trailingslashit( $plugin_path ) . 'vendor/composer/jetpack_autoload_classmap.php'; |
|
| 71 | - if ( ! file_exists( $classmap ) ) { |
|
| 69 | + public function get_autoloader_version($plugin_path) { |
|
| 70 | + $classmap = trailingslashit($plugin_path) . 'vendor/composer/jetpack_autoload_classmap.php'; |
|
| 71 | + if (!file_exists($classmap)) { |
|
| 72 | 72 | return null; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | $classmap = require $classmap; |
| 76 | - if ( isset( $classmap[ AutoloadGenerator::class ] ) ) { |
|
| 77 | - return $classmap[ AutoloadGenerator::class ]['version']; |
|
| 76 | + if (isset($classmap[AutoloadGenerator::class])) { |
|
| 77 | + return $classmap[AutoloadGenerator::class]['version']; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | return null; |
@@ -6,137 +6,137 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class Container { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * Since each autoloader's class files exist within their own namespace we need a map to |
|
| 11 | - * convert between the local class and a shared key. Note that no version checking is |
|
| 12 | - * performed on these dependencies and the first autoloader to register will be the |
|
| 13 | - * one that is utilized. |
|
| 14 | - */ |
|
| 15 | - const SHARED_DEPENDENCY_KEYS = array( |
|
| 16 | - Hook_Manager::class => 'Hook_Manager', |
|
| 17 | - ); |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * A map of all the dependencies we've registered with the container and created. |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $dependencies; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * The constructor. |
|
| 28 | - */ |
|
| 29 | - public function __construct() { |
|
| 30 | - $this->dependencies = array(); |
|
| 31 | - |
|
| 32 | - $this->register_shared_dependencies(); |
|
| 33 | - $this->register_dependencies(); |
|
| 34 | - $this->initialize_globals(); |
|
| 35 | - } |
|
| 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 | - |
|
| 50 | - return $this->dependencies[ $class ]; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Registers all of the dependencies that are shared between all instances of the autoloader. |
|
| 55 | - */ |
|
| 56 | - private function register_shared_dependencies() { |
|
| 57 | - global $jetpack_autoloader_container_shared; |
|
| 58 | - if ( ! isset( $jetpack_autoloader_container_shared ) ) { |
|
| 59 | - $jetpack_autoloader_container_shared = array(); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - $key = self::SHARED_DEPENDENCY_KEYS[ Hook_Manager::class ]; |
|
| 63 | - if ( ! isset( $jetpack_autoloader_container_shared[ $key ] ) ) { |
|
| 64 | - require_once __DIR__ . '/class-hook-manager.php'; |
|
| 65 | - $jetpack_autoloader_container_shared[ $key ] = new Hook_Manager(); |
|
| 66 | - } |
|
| 67 | - $this->dependencies[ Hook_Manager::class ] = &$jetpack_autoloader_container_shared[ $key ]; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Registers all of the dependencies with the container. |
|
| 72 | - */ |
|
| 73 | - private function register_dependencies() { |
|
| 74 | - require_once __DIR__ . '/class-path-processor.php'; |
|
| 75 | - $this->dependencies[ Path_Processor::class ] = new Path_Processor(); |
|
| 76 | - |
|
| 77 | - require_once __DIR__ . '/class-plugin-locator.php'; |
|
| 78 | - $this->dependencies[ Plugin_Locator::class ] = new Plugin_Locator( |
|
| 79 | - $this->get( Path_Processor::class ) |
|
| 80 | - ); |
|
| 81 | - |
|
| 82 | - require_once __DIR__ . '/class-version-selector.php'; |
|
| 83 | - $this->dependencies[ Version_Selector::class ] = new Version_Selector(); |
|
| 84 | - |
|
| 85 | - require_once __DIR__ . '/class-autoloader-locator.php'; |
|
| 86 | - $this->dependencies[ Autoloader_Locator::class ] = new Autoloader_Locator( |
|
| 87 | - $this->get( Version_Selector::class ) |
|
| 88 | - ); |
|
| 89 | - |
|
| 90 | - require_once __DIR__ . '/class-php-autoloader.php'; |
|
| 91 | - $this->dependencies[ PHP_Autoloader::class ] = new PHP_Autoloader(); |
|
| 92 | - |
|
| 93 | - require_once __DIR__ . '/class-manifest-reader.php'; |
|
| 94 | - $this->dependencies[ Manifest_Reader::class ] = new Manifest_Reader( |
|
| 95 | - $this->get( Version_Selector::class ) |
|
| 96 | - ); |
|
| 97 | - |
|
| 98 | - require_once __DIR__ . '/class-plugins-handler.php'; |
|
| 99 | - $this->dependencies[ Plugins_Handler::class ] = new Plugins_Handler( |
|
| 100 | - $this->get( Plugin_Locator::class ), |
|
| 101 | - $this->get( Path_Processor::class ) |
|
| 102 | - ); |
|
| 103 | - |
|
| 104 | - require_once __DIR__ . '/class-autoloader-handler.php'; |
|
| 105 | - $this->dependencies[ Autoloader_Handler::class ] = new Autoloader_Handler( |
|
| 106 | - $this->get( PHP_Autoloader::class ), |
|
| 107 | - $this->get( Hook_Manager::class ), |
|
| 108 | - $this->get( Manifest_Reader::class ), |
|
| 109 | - $this->get( Version_Selector::class ) |
|
| 110 | - ); |
|
| 111 | - |
|
| 112 | - require_once __DIR__ . '/class-latest-autoloader-guard.php'; |
|
| 113 | - $this->dependencies[ Latest_Autoloader_Guard::class ] = new Latest_Autoloader_Guard( |
|
| 114 | - $this->get( Plugins_Handler::class ), |
|
| 115 | - $this->get( Autoloader_Handler::class ), |
|
| 116 | - $this->get( Autoloader_Locator::class ) |
|
| 117 | - ); |
|
| 118 | - |
|
| 119 | - // Register any classes that we will use elsewhere. |
|
| 120 | - require_once __DIR__ . '/class-version-loader.php'; |
|
| 121 | - require_once __DIR__ . '/class-shutdown-handler.php'; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Initializes any of the globals needed by the autoloader. |
|
| 126 | - */ |
|
| 127 | - private function initialize_globals() { |
|
| 128 | - /* |
|
| 9 | + /** |
|
| 10 | + * Since each autoloader's class files exist within their own namespace we need a map to |
|
| 11 | + * convert between the local class and a shared key. Note that no version checking is |
|
| 12 | + * performed on these dependencies and the first autoloader to register will be the |
|
| 13 | + * one that is utilized. |
|
| 14 | + */ |
|
| 15 | + const SHARED_DEPENDENCY_KEYS = array( |
|
| 16 | + Hook_Manager::class => 'Hook_Manager', |
|
| 17 | + ); |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * A map of all the dependencies we've registered with the container and created. |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $dependencies; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * The constructor. |
|
| 28 | + */ |
|
| 29 | + public function __construct() { |
|
| 30 | + $this->dependencies = array(); |
|
| 31 | + |
|
| 32 | + $this->register_shared_dependencies(); |
|
| 33 | + $this->register_dependencies(); |
|
| 34 | + $this->initialize_globals(); |
|
| 35 | + } |
|
| 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 | + |
|
| 50 | + return $this->dependencies[ $class ]; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Registers all of the dependencies that are shared between all instances of the autoloader. |
|
| 55 | + */ |
|
| 56 | + private function register_shared_dependencies() { |
|
| 57 | + global $jetpack_autoloader_container_shared; |
|
| 58 | + if ( ! isset( $jetpack_autoloader_container_shared ) ) { |
|
| 59 | + $jetpack_autoloader_container_shared = array(); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + $key = self::SHARED_DEPENDENCY_KEYS[ Hook_Manager::class ]; |
|
| 63 | + if ( ! isset( $jetpack_autoloader_container_shared[ $key ] ) ) { |
|
| 64 | + require_once __DIR__ . '/class-hook-manager.php'; |
|
| 65 | + $jetpack_autoloader_container_shared[ $key ] = new Hook_Manager(); |
|
| 66 | + } |
|
| 67 | + $this->dependencies[ Hook_Manager::class ] = &$jetpack_autoloader_container_shared[ $key ]; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Registers all of the dependencies with the container. |
|
| 72 | + */ |
|
| 73 | + private function register_dependencies() { |
|
| 74 | + require_once __DIR__ . '/class-path-processor.php'; |
|
| 75 | + $this->dependencies[ Path_Processor::class ] = new Path_Processor(); |
|
| 76 | + |
|
| 77 | + require_once __DIR__ . '/class-plugin-locator.php'; |
|
| 78 | + $this->dependencies[ Plugin_Locator::class ] = new Plugin_Locator( |
|
| 79 | + $this->get( Path_Processor::class ) |
|
| 80 | + ); |
|
| 81 | + |
|
| 82 | + require_once __DIR__ . '/class-version-selector.php'; |
|
| 83 | + $this->dependencies[ Version_Selector::class ] = new Version_Selector(); |
|
| 84 | + |
|
| 85 | + require_once __DIR__ . '/class-autoloader-locator.php'; |
|
| 86 | + $this->dependencies[ Autoloader_Locator::class ] = new Autoloader_Locator( |
|
| 87 | + $this->get( Version_Selector::class ) |
|
| 88 | + ); |
|
| 89 | + |
|
| 90 | + require_once __DIR__ . '/class-php-autoloader.php'; |
|
| 91 | + $this->dependencies[ PHP_Autoloader::class ] = new PHP_Autoloader(); |
|
| 92 | + |
|
| 93 | + require_once __DIR__ . '/class-manifest-reader.php'; |
|
| 94 | + $this->dependencies[ Manifest_Reader::class ] = new Manifest_Reader( |
|
| 95 | + $this->get( Version_Selector::class ) |
|
| 96 | + ); |
|
| 97 | + |
|
| 98 | + require_once __DIR__ . '/class-plugins-handler.php'; |
|
| 99 | + $this->dependencies[ Plugins_Handler::class ] = new Plugins_Handler( |
|
| 100 | + $this->get( Plugin_Locator::class ), |
|
| 101 | + $this->get( Path_Processor::class ) |
|
| 102 | + ); |
|
| 103 | + |
|
| 104 | + require_once __DIR__ . '/class-autoloader-handler.php'; |
|
| 105 | + $this->dependencies[ Autoloader_Handler::class ] = new Autoloader_Handler( |
|
| 106 | + $this->get( PHP_Autoloader::class ), |
|
| 107 | + $this->get( Hook_Manager::class ), |
|
| 108 | + $this->get( Manifest_Reader::class ), |
|
| 109 | + $this->get( Version_Selector::class ) |
|
| 110 | + ); |
|
| 111 | + |
|
| 112 | + require_once __DIR__ . '/class-latest-autoloader-guard.php'; |
|
| 113 | + $this->dependencies[ Latest_Autoloader_Guard::class ] = new Latest_Autoloader_Guard( |
|
| 114 | + $this->get( Plugins_Handler::class ), |
|
| 115 | + $this->get( Autoloader_Handler::class ), |
|
| 116 | + $this->get( Autoloader_Locator::class ) |
|
| 117 | + ); |
|
| 118 | + |
|
| 119 | + // Register any classes that we will use elsewhere. |
|
| 120 | + require_once __DIR__ . '/class-version-loader.php'; |
|
| 121 | + require_once __DIR__ . '/class-shutdown-handler.php'; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Initializes any of the globals needed by the autoloader. |
|
| 126 | + */ |
|
| 127 | + private function initialize_globals() { |
|
| 128 | + /* |
|
| 129 | 129 | * This global was retired in version 2.9. The value is set to 'false' to maintain |
| 130 | 130 | * compatibility with older versions of the autoloader. |
| 131 | 131 | */ |
| 132 | - global $jetpack_autoloader_including_latest; |
|
| 133 | - $jetpack_autoloader_including_latest = false; |
|
| 134 | - |
|
| 135 | - // Not all plugins can be found using the locator. In cases where a plugin loads the autoloader |
|
| 136 | - // but was not discoverable, we will record them in this array to track them as "active". |
|
| 137 | - global $jetpack_autoloader_activating_plugins_paths; |
|
| 138 | - if ( ! isset( $jetpack_autoloader_activating_plugins_paths ) ) { |
|
| 139 | - $jetpack_autoloader_activating_plugins_paths = array(); |
|
| 140 | - } |
|
| 141 | - } |
|
| 132 | + global $jetpack_autoloader_including_latest; |
|
| 133 | + $jetpack_autoloader_including_latest = false; |
|
| 134 | + |
|
| 135 | + // Not all plugins can be found using the locator. In cases where a plugin loads the autoloader |
|
| 136 | + // but was not discoverable, we will record them in this array to track them as "active". |
|
| 137 | + global $jetpack_autoloader_activating_plugins_paths; |
|
| 138 | + if ( ! isset( $jetpack_autoloader_activating_plugins_paths ) ) { |
|
| 139 | + $jetpack_autoloader_activating_plugins_paths = array(); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | 142 | } |
@@ -42,12 +42,12 @@ discard block |
||
| 42 | 42 | * @return mixed |
| 43 | 43 | * @throws \InvalidArgumentException When a class that isn't registered with the container is fetched. |
| 44 | 44 | */ |
| 45 | - public function get( $class ) { |
|
| 46 | - if ( ! isset( $this->dependencies[ $class ] ) ) { |
|
| 47 | - throw new \InvalidArgumentException( "Class '$class' is not registered with the container." ); |
|
| 45 | + public function get($class) { |
|
| 46 | + if (!isset($this->dependencies[$class])) { |
|
| 47 | + throw new \InvalidArgumentException("Class '$class' is not registered with the container."); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - return $this->dependencies[ $class ]; |
|
| 50 | + return $this->dependencies[$class]; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -55,16 +55,16 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | private function register_shared_dependencies() { |
| 57 | 57 | global $jetpack_autoloader_container_shared; |
| 58 | - if ( ! isset( $jetpack_autoloader_container_shared ) ) { |
|
| 58 | + if (!isset($jetpack_autoloader_container_shared)) { |
|
| 59 | 59 | $jetpack_autoloader_container_shared = array(); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $key = self::SHARED_DEPENDENCY_KEYS[ Hook_Manager::class ]; |
|
| 63 | - if ( ! isset( $jetpack_autoloader_container_shared[ $key ] ) ) { |
|
| 62 | + $key = self::SHARED_DEPENDENCY_KEYS[Hook_Manager::class]; |
|
| 63 | + if (!isset($jetpack_autoloader_container_shared[$key])) { |
|
| 64 | 64 | require_once __DIR__ . '/class-hook-manager.php'; |
| 65 | - $jetpack_autoloader_container_shared[ $key ] = new Hook_Manager(); |
|
| 65 | + $jetpack_autoloader_container_shared[$key] = new Hook_Manager(); |
|
| 66 | 66 | } |
| 67 | - $this->dependencies[ Hook_Manager::class ] = &$jetpack_autoloader_container_shared[ $key ]; |
|
| 67 | + $this->dependencies[Hook_Manager::class] = &$jetpack_autoloader_container_shared[$key]; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -72,48 +72,48 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | private function register_dependencies() { |
| 74 | 74 | require_once __DIR__ . '/class-path-processor.php'; |
| 75 | - $this->dependencies[ Path_Processor::class ] = new Path_Processor(); |
|
| 75 | + $this->dependencies[Path_Processor::class] = new Path_Processor(); |
|
| 76 | 76 | |
| 77 | 77 | require_once __DIR__ . '/class-plugin-locator.php'; |
| 78 | - $this->dependencies[ Plugin_Locator::class ] = new Plugin_Locator( |
|
| 79 | - $this->get( Path_Processor::class ) |
|
| 78 | + $this->dependencies[Plugin_Locator::class] = new Plugin_Locator( |
|
| 79 | + $this->get(Path_Processor::class) |
|
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | 82 | require_once __DIR__ . '/class-version-selector.php'; |
| 83 | - $this->dependencies[ Version_Selector::class ] = new Version_Selector(); |
|
| 83 | + $this->dependencies[Version_Selector::class] = new Version_Selector(); |
|
| 84 | 84 | |
| 85 | 85 | require_once __DIR__ . '/class-autoloader-locator.php'; |
| 86 | - $this->dependencies[ Autoloader_Locator::class ] = new Autoloader_Locator( |
|
| 87 | - $this->get( Version_Selector::class ) |
|
| 86 | + $this->dependencies[Autoloader_Locator::class] = new Autoloader_Locator( |
|
| 87 | + $this->get(Version_Selector::class) |
|
| 88 | 88 | ); |
| 89 | 89 | |
| 90 | 90 | require_once __DIR__ . '/class-php-autoloader.php'; |
| 91 | - $this->dependencies[ PHP_Autoloader::class ] = new PHP_Autoloader(); |
|
| 91 | + $this->dependencies[PHP_Autoloader::class] = new PHP_Autoloader(); |
|
| 92 | 92 | |
| 93 | 93 | require_once __DIR__ . '/class-manifest-reader.php'; |
| 94 | - $this->dependencies[ Manifest_Reader::class ] = new Manifest_Reader( |
|
| 95 | - $this->get( Version_Selector::class ) |
|
| 94 | + $this->dependencies[Manifest_Reader::class] = new Manifest_Reader( |
|
| 95 | + $this->get(Version_Selector::class) |
|
| 96 | 96 | ); |
| 97 | 97 | |
| 98 | 98 | require_once __DIR__ . '/class-plugins-handler.php'; |
| 99 | - $this->dependencies[ Plugins_Handler::class ] = new Plugins_Handler( |
|
| 100 | - $this->get( Plugin_Locator::class ), |
|
| 101 | - $this->get( Path_Processor::class ) |
|
| 99 | + $this->dependencies[Plugins_Handler::class] = new Plugins_Handler( |
|
| 100 | + $this->get(Plugin_Locator::class), |
|
| 101 | + $this->get(Path_Processor::class) |
|
| 102 | 102 | ); |
| 103 | 103 | |
| 104 | 104 | require_once __DIR__ . '/class-autoloader-handler.php'; |
| 105 | - $this->dependencies[ Autoloader_Handler::class ] = new Autoloader_Handler( |
|
| 106 | - $this->get( PHP_Autoloader::class ), |
|
| 107 | - $this->get( Hook_Manager::class ), |
|
| 108 | - $this->get( Manifest_Reader::class ), |
|
| 109 | - $this->get( Version_Selector::class ) |
|
| 105 | + $this->dependencies[Autoloader_Handler::class] = new Autoloader_Handler( |
|
| 106 | + $this->get(PHP_Autoloader::class), |
|
| 107 | + $this->get(Hook_Manager::class), |
|
| 108 | + $this->get(Manifest_Reader::class), |
|
| 109 | + $this->get(Version_Selector::class) |
|
| 110 | 110 | ); |
| 111 | 111 | |
| 112 | 112 | require_once __DIR__ . '/class-latest-autoloader-guard.php'; |
| 113 | - $this->dependencies[ Latest_Autoloader_Guard::class ] = new Latest_Autoloader_Guard( |
|
| 114 | - $this->get( Plugins_Handler::class ), |
|
| 115 | - $this->get( Autoloader_Handler::class ), |
|
| 116 | - $this->get( Autoloader_Locator::class ) |
|
| 113 | + $this->dependencies[Latest_Autoloader_Guard::class] = new Latest_Autoloader_Guard( |
|
| 114 | + $this->get(Plugins_Handler::class), |
|
| 115 | + $this->get(Autoloader_Handler::class), |
|
| 116 | + $this->get(Autoloader_Locator::class) |
|
| 117 | 117 | ); |
| 118 | 118 | |
| 119 | 119 | // Register any classes that we will use elsewhere. |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | // Not all plugins can be found using the locator. In cases where a plugin loads the autoloader |
| 136 | 136 | // but was not discoverable, we will record them in this array to track them as "active". |
| 137 | 137 | global $jetpack_autoloader_activating_plugins_paths; |
| 138 | - if ( ! isset( $jetpack_autoloader_activating_plugins_paths ) ) { |
|
| 138 | + if (!isset($jetpack_autoloader_activating_plugins_paths)) { |
|
| 139 | 139 | $jetpack_autoloader_activating_plugins_paths = array(); |
| 140 | 140 | } |
| 141 | 141 | } |
@@ -6,140 +6,140 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class Plugin_Locator { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * The path processor for finding plugin paths. |
|
| 11 | - * |
|
| 12 | - * @var Path_Processor |
|
| 13 | - */ |
|
| 14 | - private $path_processor; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * The constructor. |
|
| 18 | - * |
|
| 19 | - * @param Path_Processor $path_processor The Path_Processor instance. |
|
| 20 | - */ |
|
| 21 | - public function __construct( $path_processor ) { |
|
| 22 | - $this->path_processor = $path_processor; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Finds the path to the current plugin. |
|
| 27 | - * |
|
| 28 | - * @return string $path The path to the current plugin. |
|
| 29 | - * |
|
| 30 | - * @throws \RuntimeException If the current plugin does not have an autoloader. |
|
| 31 | - */ |
|
| 32 | - public function find_current_plugin() { |
|
| 33 | - // Escape from `vendor/__DIR__` to root plugin directory. |
|
| 34 | - $plugin_directory = dirname( dirname( __DIR__ ) ); |
|
| 35 | - |
|
| 36 | - // Use the path processor to ensure that this is an autoloader we're referencing. |
|
| 37 | - $path = $this->path_processor->find_directory_with_autoloader( $plugin_directory, array() ); |
|
| 38 | - if ( false === $path ) { |
|
| 39 | - throw new \RuntimeException( 'Failed to locate plugin ' . $plugin_directory ); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - return $path; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Checks a given option for plugin paths. |
|
| 47 | - * |
|
| 48 | - * @param string $option_name The option that we want to check for plugin information. |
|
| 49 | - * @param bool $site_option Indicates whether or not we want to check the site option. |
|
| 50 | - * |
|
| 51 | - * @return array $plugin_paths The list of absolute paths we've found. |
|
| 52 | - */ |
|
| 53 | - public function find_using_option( $option_name, $site_option = false ) { |
|
| 54 | - $raw = $site_option ? get_site_option( $option_name ) : get_option( $option_name ); |
|
| 55 | - if ( false === $raw ) { |
|
| 56 | - return array(); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - return $this->convert_plugins_to_paths( $raw ); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Checks for plugins in the `action` request parameter. |
|
| 64 | - * |
|
| 65 | - * @param string[] $allowed_actions The actions that we're allowed to return plugins for. |
|
| 66 | - * |
|
| 67 | - * @return array $plugin_paths The list of absolute paths we've found. |
|
| 68 | - */ |
|
| 69 | - public function find_using_request_action( $allowed_actions ) { |
|
| 70 | - // phpcs:disable WordPress.Security.NonceVerification.Recommended |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Note: we're not actually checking the nonce here because it's too early |
|
| 74 | - * in the execution. The pluggable functions are not yet loaded to give |
|
| 75 | - * plugins a chance to plug their versions. Therefore we're doing the bare |
|
| 76 | - * minimum: checking whether the nonce exists and it's in the right place. |
|
| 77 | - * The request will fail later if the nonce doesn't pass the check. |
|
| 78 | - */ |
|
| 79 | - if ( empty( $_REQUEST['_wpnonce'] ) ) { |
|
| 80 | - return array(); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - $action = isset( $_REQUEST['action'] ) ? wp_unslash( $_REQUEST['action'] ) : false; |
|
| 84 | - if ( ! in_array( $action, $allowed_actions, true ) ) { |
|
| 85 | - return array(); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $plugin_slugs = array(); |
|
| 89 | - switch ( $action ) { |
|
| 90 | - case 'activate': |
|
| 91 | - case 'deactivate': |
|
| 92 | - if ( empty( $_REQUEST['plugin'] ) ) { |
|
| 93 | - break; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $plugin_slugs[] = wp_unslash( $_REQUEST['plugin'] ); |
|
| 97 | - break; |
|
| 98 | - |
|
| 99 | - case 'activate-selected': |
|
| 100 | - case 'deactivate-selected': |
|
| 101 | - if ( empty( $_REQUEST['checked'] ) ) { |
|
| 102 | - break; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $plugin_slugs = wp_unslash( $_REQUEST['checked'] ); |
|
| 106 | - break; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // phpcs:enable WordPress.Security.NonceVerification.Recommended |
|
| 110 | - return $this->convert_plugins_to_paths( $plugin_slugs ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Given an array of plugin slugs or paths, this will convert them to absolute paths and filter |
|
| 115 | - * out the plugins that are not directory plugins. Note that array keys will also be included |
|
| 116 | - * if they are plugin paths! |
|
| 117 | - * |
|
| 118 | - * @param string[] $plugins Plugin paths or slugs to filter. |
|
| 119 | - * |
|
| 120 | - * @return string[] |
|
| 121 | - */ |
|
| 122 | - private function convert_plugins_to_paths( $plugins ) { |
|
| 123 | - if ( ! is_array( $plugins ) || empty( $plugins ) ) { |
|
| 124 | - return array(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // We're going to look for plugins in the standard directories. |
|
| 128 | - $path_constants = array( WP_PLUGIN_DIR, WPMU_PLUGIN_DIR ); |
|
| 129 | - |
|
| 130 | - $plugin_paths = array(); |
|
| 131 | - foreach ( $plugins as $key => $value ) { |
|
| 132 | - $path = $this->path_processor->find_directory_with_autoloader( $key, $path_constants ); |
|
| 133 | - if ( $path ) { |
|
| 134 | - $plugin_paths[] = $path; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $path = $this->path_processor->find_directory_with_autoloader( $value, $path_constants ); |
|
| 138 | - if ( $path ) { |
|
| 139 | - $plugin_paths[] = $path; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $plugin_paths; |
|
| 144 | - } |
|
| 9 | + /** |
|
| 10 | + * The path processor for finding plugin paths. |
|
| 11 | + * |
|
| 12 | + * @var Path_Processor |
|
| 13 | + */ |
|
| 14 | + private $path_processor; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * The constructor. |
|
| 18 | + * |
|
| 19 | + * @param Path_Processor $path_processor The Path_Processor instance. |
|
| 20 | + */ |
|
| 21 | + public function __construct( $path_processor ) { |
|
| 22 | + $this->path_processor = $path_processor; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Finds the path to the current plugin. |
|
| 27 | + * |
|
| 28 | + * @return string $path The path to the current plugin. |
|
| 29 | + * |
|
| 30 | + * @throws \RuntimeException If the current plugin does not have an autoloader. |
|
| 31 | + */ |
|
| 32 | + public function find_current_plugin() { |
|
| 33 | + // Escape from `vendor/__DIR__` to root plugin directory. |
|
| 34 | + $plugin_directory = dirname( dirname( __DIR__ ) ); |
|
| 35 | + |
|
| 36 | + // Use the path processor to ensure that this is an autoloader we're referencing. |
|
| 37 | + $path = $this->path_processor->find_directory_with_autoloader( $plugin_directory, array() ); |
|
| 38 | + if ( false === $path ) { |
|
| 39 | + throw new \RuntimeException( 'Failed to locate plugin ' . $plugin_directory ); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + return $path; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Checks a given option for plugin paths. |
|
| 47 | + * |
|
| 48 | + * @param string $option_name The option that we want to check for plugin information. |
|
| 49 | + * @param bool $site_option Indicates whether or not we want to check the site option. |
|
| 50 | + * |
|
| 51 | + * @return array $plugin_paths The list of absolute paths we've found. |
|
| 52 | + */ |
|
| 53 | + public function find_using_option( $option_name, $site_option = false ) { |
|
| 54 | + $raw = $site_option ? get_site_option( $option_name ) : get_option( $option_name ); |
|
| 55 | + if ( false === $raw ) { |
|
| 56 | + return array(); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + return $this->convert_plugins_to_paths( $raw ); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Checks for plugins in the `action` request parameter. |
|
| 64 | + * |
|
| 65 | + * @param string[] $allowed_actions The actions that we're allowed to return plugins for. |
|
| 66 | + * |
|
| 67 | + * @return array $plugin_paths The list of absolute paths we've found. |
|
| 68 | + */ |
|
| 69 | + public function find_using_request_action( $allowed_actions ) { |
|
| 70 | + // phpcs:disable WordPress.Security.NonceVerification.Recommended |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Note: we're not actually checking the nonce here because it's too early |
|
| 74 | + * in the execution. The pluggable functions are not yet loaded to give |
|
| 75 | + * plugins a chance to plug their versions. Therefore we're doing the bare |
|
| 76 | + * minimum: checking whether the nonce exists and it's in the right place. |
|
| 77 | + * The request will fail later if the nonce doesn't pass the check. |
|
| 78 | + */ |
|
| 79 | + if ( empty( $_REQUEST['_wpnonce'] ) ) { |
|
| 80 | + return array(); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + $action = isset( $_REQUEST['action'] ) ? wp_unslash( $_REQUEST['action'] ) : false; |
|
| 84 | + if ( ! in_array( $action, $allowed_actions, true ) ) { |
|
| 85 | + return array(); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $plugin_slugs = array(); |
|
| 89 | + switch ( $action ) { |
|
| 90 | + case 'activate': |
|
| 91 | + case 'deactivate': |
|
| 92 | + if ( empty( $_REQUEST['plugin'] ) ) { |
|
| 93 | + break; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $plugin_slugs[] = wp_unslash( $_REQUEST['plugin'] ); |
|
| 97 | + break; |
|
| 98 | + |
|
| 99 | + case 'activate-selected': |
|
| 100 | + case 'deactivate-selected': |
|
| 101 | + if ( empty( $_REQUEST['checked'] ) ) { |
|
| 102 | + break; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $plugin_slugs = wp_unslash( $_REQUEST['checked'] ); |
|
| 106 | + break; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // phpcs:enable WordPress.Security.NonceVerification.Recommended |
|
| 110 | + return $this->convert_plugins_to_paths( $plugin_slugs ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Given an array of plugin slugs or paths, this will convert them to absolute paths and filter |
|
| 115 | + * out the plugins that are not directory plugins. Note that array keys will also be included |
|
| 116 | + * if they are plugin paths! |
|
| 117 | + * |
|
| 118 | + * @param string[] $plugins Plugin paths or slugs to filter. |
|
| 119 | + * |
|
| 120 | + * @return string[] |
|
| 121 | + */ |
|
| 122 | + private function convert_plugins_to_paths( $plugins ) { |
|
| 123 | + if ( ! is_array( $plugins ) || empty( $plugins ) ) { |
|
| 124 | + return array(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // We're going to look for plugins in the standard directories. |
|
| 128 | + $path_constants = array( WP_PLUGIN_DIR, WPMU_PLUGIN_DIR ); |
|
| 129 | + |
|
| 130 | + $plugin_paths = array(); |
|
| 131 | + foreach ( $plugins as $key => $value ) { |
|
| 132 | + $path = $this->path_processor->find_directory_with_autoloader( $key, $path_constants ); |
|
| 133 | + if ( $path ) { |
|
| 134 | + $plugin_paths[] = $path; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $path = $this->path_processor->find_directory_with_autoloader( $value, $path_constants ); |
|
| 138 | + if ( $path ) { |
|
| 139 | + $plugin_paths[] = $path; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $plugin_paths; |
|
| 144 | + } |
|
| 145 | 145 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @param Path_Processor $path_processor The Path_Processor instance. |
| 20 | 20 | */ |
| 21 | - public function __construct( $path_processor ) { |
|
| 21 | + public function __construct($path_processor) { |
|
| 22 | 22 | $this->path_processor = $path_processor; |
| 23 | 23 | } |
| 24 | 24 | |
@@ -31,12 +31,12 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public function find_current_plugin() { |
| 33 | 33 | // Escape from `vendor/__DIR__` to root plugin directory. |
| 34 | - $plugin_directory = dirname( dirname( __DIR__ ) ); |
|
| 34 | + $plugin_directory = dirname(dirname(__DIR__)); |
|
| 35 | 35 | |
| 36 | 36 | // Use the path processor to ensure that this is an autoloader we're referencing. |
| 37 | - $path = $this->path_processor->find_directory_with_autoloader( $plugin_directory, array() ); |
|
| 38 | - if ( false === $path ) { |
|
| 39 | - throw new \RuntimeException( 'Failed to locate plugin ' . $plugin_directory ); |
|
| 37 | + $path = $this->path_processor->find_directory_with_autoloader($plugin_directory, array()); |
|
| 38 | + if (false === $path) { |
|
| 39 | + throw new \RuntimeException('Failed to locate plugin ' . $plugin_directory); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | return $path; |
@@ -50,13 +50,13 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return array $plugin_paths The list of absolute paths we've found. |
| 52 | 52 | */ |
| 53 | - public function find_using_option( $option_name, $site_option = false ) { |
|
| 54 | - $raw = $site_option ? get_site_option( $option_name ) : get_option( $option_name ); |
|
| 55 | - if ( false === $raw ) { |
|
| 53 | + public function find_using_option($option_name, $site_option = false) { |
|
| 54 | + $raw = $site_option ? get_site_option($option_name) : get_option($option_name); |
|
| 55 | + if (false === $raw) { |
|
| 56 | 56 | return array(); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - return $this->convert_plugins_to_paths( $raw ); |
|
| 59 | + return $this->convert_plugins_to_paths($raw); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @return array $plugin_paths The list of absolute paths we've found. |
| 68 | 68 | */ |
| 69 | - public function find_using_request_action( $allowed_actions ) { |
|
| 69 | + public function find_using_request_action($allowed_actions) { |
|
| 70 | 70 | // phpcs:disable WordPress.Security.NonceVerification.Recommended |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -76,38 +76,38 @@ discard block |
||
| 76 | 76 | * minimum: checking whether the nonce exists and it's in the right place. |
| 77 | 77 | * The request will fail later if the nonce doesn't pass the check. |
| 78 | 78 | */ |
| 79 | - if ( empty( $_REQUEST['_wpnonce'] ) ) { |
|
| 79 | + if (empty($_REQUEST['_wpnonce'])) { |
|
| 80 | 80 | return array(); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - $action = isset( $_REQUEST['action'] ) ? wp_unslash( $_REQUEST['action'] ) : false; |
|
| 84 | - if ( ! in_array( $action, $allowed_actions, true ) ) { |
|
| 83 | + $action = isset($_REQUEST['action']) ? wp_unslash($_REQUEST['action']) : false; |
|
| 84 | + if (!in_array($action, $allowed_actions, true)) { |
|
| 85 | 85 | return array(); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | $plugin_slugs = array(); |
| 89 | - switch ( $action ) { |
|
| 89 | + switch ($action) { |
|
| 90 | 90 | case 'activate': |
| 91 | 91 | case 'deactivate': |
| 92 | - if ( empty( $_REQUEST['plugin'] ) ) { |
|
| 92 | + if (empty($_REQUEST['plugin'])) { |
|
| 93 | 93 | break; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - $plugin_slugs[] = wp_unslash( $_REQUEST['plugin'] ); |
|
| 96 | + $plugin_slugs[] = wp_unslash($_REQUEST['plugin']); |
|
| 97 | 97 | break; |
| 98 | 98 | |
| 99 | 99 | case 'activate-selected': |
| 100 | 100 | case 'deactivate-selected': |
| 101 | - if ( empty( $_REQUEST['checked'] ) ) { |
|
| 101 | + if (empty($_REQUEST['checked'])) { |
|
| 102 | 102 | break; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - $plugin_slugs = wp_unslash( $_REQUEST['checked'] ); |
|
| 105 | + $plugin_slugs = wp_unslash($_REQUEST['checked']); |
|
| 106 | 106 | break; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // phpcs:enable WordPress.Security.NonceVerification.Recommended |
| 110 | - return $this->convert_plugins_to_paths( $plugin_slugs ); |
|
| 110 | + return $this->convert_plugins_to_paths($plugin_slugs); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -119,23 +119,23 @@ discard block |
||
| 119 | 119 | * |
| 120 | 120 | * @return string[] |
| 121 | 121 | */ |
| 122 | - private function convert_plugins_to_paths( $plugins ) { |
|
| 123 | - if ( ! is_array( $plugins ) || empty( $plugins ) ) { |
|
| 122 | + private function convert_plugins_to_paths($plugins) { |
|
| 123 | + if (!is_array($plugins) || empty($plugins)) { |
|
| 124 | 124 | return array(); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // We're going to look for plugins in the standard directories. |
| 128 | - $path_constants = array( WP_PLUGIN_DIR, WPMU_PLUGIN_DIR ); |
|
| 128 | + $path_constants = array(WP_PLUGIN_DIR, WPMU_PLUGIN_DIR); |
|
| 129 | 129 | |
| 130 | 130 | $plugin_paths = array(); |
| 131 | - foreach ( $plugins as $key => $value ) { |
|
| 132 | - $path = $this->path_processor->find_directory_with_autoloader( $key, $path_constants ); |
|
| 133 | - if ( $path ) { |
|
| 131 | + foreach ($plugins as $key => $value) { |
|
| 132 | + $path = $this->path_processor->find_directory_with_autoloader($key, $path_constants); |
|
| 133 | + if ($path) { |
|
| 134 | 134 | $plugin_paths[] = $path; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $path = $this->path_processor->find_directory_with_autoloader( $value, $path_constants ); |
|
| 138 | - if ( $path ) { |
|
| 137 | + $path = $this->path_processor->find_directory_with_autoloader($value, $path_constants); |
|
| 138 | + if ($path) { |
|
| 139 | 139 | $plugin_paths[] = $path; |
| 140 | 140 | } |
| 141 | 141 | } |
@@ -6,151 +6,151 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class Version_Loader { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * The Version_Selector object. |
|
| 11 | - * |
|
| 12 | - * @var Version_Selector |
|
| 13 | - */ |
|
| 14 | - private $version_selector; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * A map of available classes and their version and file path. |
|
| 18 | - * |
|
| 19 | - * @var array |
|
| 20 | - */ |
|
| 21 | - private $classmap; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * A map of PSR-4 namespaces and their version and directory path. |
|
| 25 | - * |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - private $psr4_map; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * A map of all the files that we should load. |
|
| 32 | - * |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 35 | - private $filemap; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * The constructor. |
|
| 39 | - * |
|
| 40 | - * @param Version_Selector $version_selector The Version_Selector object. |
|
| 41 | - * @param array $classmap The verioned classmap to load using. |
|
| 42 | - * @param array $psr4_map The versioned PSR-4 map to load using. |
|
| 43 | - * @param array $filemap The versioned filemap to load. |
|
| 44 | - */ |
|
| 45 | - public function __construct( $version_selector, $classmap, $psr4_map, $filemap ) { |
|
| 46 | - $this->version_selector = $version_selector; |
|
| 47 | - $this->classmap = $classmap; |
|
| 48 | - $this->psr4_map = $psr4_map; |
|
| 49 | - $this->filemap = $filemap; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Finds the file path for the given class. |
|
| 54 | - * |
|
| 55 | - * @param string $class_name The class to find. |
|
| 56 | - * |
|
| 57 | - * @return string|null $file_path The path to the file if found, null if no class was found. |
|
| 58 | - */ |
|
| 59 | - public function find_class_file( $class_name ) { |
|
| 60 | - $data = $this->select_newest_file( |
|
| 61 | - isset( $this->classmap[ $class_name ] ) ? $this->classmap[ $class_name ] : null, |
|
| 62 | - $this->find_psr4_file( $class_name ) |
|
| 63 | - ); |
|
| 64 | - if ( ! isset( $data ) ) { |
|
| 65 | - return null; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - return $data['path']; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Load all of the files in the filemap. |
|
| 73 | - */ |
|
| 74 | - public function load_filemap() { |
|
| 75 | - if ( empty( $this->filemap ) ) { |
|
| 76 | - return; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - foreach ( $this->filemap as $file_identifier => $file_data ) { |
|
| 80 | - if ( empty( $GLOBALS['__composer_autoload_files'][ $file_identifier ] ) ) { |
|
| 81 | - require_once $file_data['path']; |
|
| 82 | - |
|
| 83 | - $GLOBALS['__composer_autoload_files'][ $file_identifier ] = true; |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Compares different class sources and returns the newest. |
|
| 90 | - * |
|
| 91 | - * @param array|null $classmap_data The classmap class data. |
|
| 92 | - * @param array|null $psr4_data The PSR-4 class data. |
|
| 93 | - * |
|
| 94 | - * @return array|null $data |
|
| 95 | - */ |
|
| 96 | - private function select_newest_file( $classmap_data, $psr4_data ) { |
|
| 97 | - if ( ! isset( $classmap_data ) ) { |
|
| 98 | - return $psr4_data; |
|
| 99 | - } elseif ( ! isset( $psr4_data ) ) { |
|
| 100 | - return $classmap_data; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - if ( $this->version_selector->is_version_update_required( $classmap_data['version'], $psr4_data['version'] ) ) { |
|
| 104 | - return $psr4_data; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return $classmap_data; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Finds the file for a given class in a PSR-4 namespace. |
|
| 112 | - * |
|
| 113 | - * @param string $class_name The class to find. |
|
| 114 | - * |
|
| 115 | - * @return array|null $data The version and path path to the file if found, null otherwise. |
|
| 116 | - */ |
|
| 117 | - private function find_psr4_file( $class_name ) { |
|
| 118 | - if ( ! isset( $this->psr4_map ) ) { |
|
| 119 | - return null; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // Don't bother with classes that have no namespace. |
|
| 123 | - $class_index = strrpos( $class_name, '\\' ); |
|
| 124 | - if ( ! $class_index ) { |
|
| 125 | - return null; |
|
| 126 | - } |
|
| 127 | - $class_for_path = str_replace( '\\', '/', $class_name ); |
|
| 128 | - |
|
| 129 | - // Search for the namespace by iteratively cutting off the last segment until |
|
| 130 | - // we find a match. This allows us to check the most-specific namespaces |
|
| 131 | - // first as well as minimize the amount of time spent looking. |
|
| 132 | - for ( |
|
| 133 | - $class_namespace = substr( $class_name, 0, $class_index ); |
|
| 134 | - ! empty( $class_namespace ); |
|
| 135 | - $class_namespace = substr( $class_namespace, 0, strrpos( $class_namespace, '\\' ) ) |
|
| 136 | - ) { |
|
| 137 | - $namespace = $class_namespace . '\\'; |
|
| 138 | - if ( ! isset( $this->psr4_map[ $namespace ] ) ) { |
|
| 139 | - continue; |
|
| 140 | - } |
|
| 141 | - $data = $this->psr4_map[ $namespace ]; |
|
| 142 | - |
|
| 143 | - foreach ( $data['path'] as $path ) { |
|
| 144 | - $path .= '/' . substr( $class_for_path, strlen( $namespace ) ) . '.php'; |
|
| 145 | - if ( file_exists( $path ) ) { |
|
| 146 | - return array( |
|
| 147 | - 'version' => $data['version'], |
|
| 148 | - 'path' => $path, |
|
| 149 | - ); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return null; |
|
| 155 | - } |
|
| 9 | + /** |
|
| 10 | + * The Version_Selector object. |
|
| 11 | + * |
|
| 12 | + * @var Version_Selector |
|
| 13 | + */ |
|
| 14 | + private $version_selector; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * A map of available classes and their version and file path. |
|
| 18 | + * |
|
| 19 | + * @var array |
|
| 20 | + */ |
|
| 21 | + private $classmap; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * A map of PSR-4 namespaces and their version and directory path. |
|
| 25 | + * |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + private $psr4_map; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * A map of all the files that we should load. |
|
| 32 | + * |
|
| 33 | + * @var array |
|
| 34 | + */ |
|
| 35 | + private $filemap; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * The constructor. |
|
| 39 | + * |
|
| 40 | + * @param Version_Selector $version_selector The Version_Selector object. |
|
| 41 | + * @param array $classmap The verioned classmap to load using. |
|
| 42 | + * @param array $psr4_map The versioned PSR-4 map to load using. |
|
| 43 | + * @param array $filemap The versioned filemap to load. |
|
| 44 | + */ |
|
| 45 | + public function __construct( $version_selector, $classmap, $psr4_map, $filemap ) { |
|
| 46 | + $this->version_selector = $version_selector; |
|
| 47 | + $this->classmap = $classmap; |
|
| 48 | + $this->psr4_map = $psr4_map; |
|
| 49 | + $this->filemap = $filemap; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Finds the file path for the given class. |
|
| 54 | + * |
|
| 55 | + * @param string $class_name The class to find. |
|
| 56 | + * |
|
| 57 | + * @return string|null $file_path The path to the file if found, null if no class was found. |
|
| 58 | + */ |
|
| 59 | + public function find_class_file( $class_name ) { |
|
| 60 | + $data = $this->select_newest_file( |
|
| 61 | + isset( $this->classmap[ $class_name ] ) ? $this->classmap[ $class_name ] : null, |
|
| 62 | + $this->find_psr4_file( $class_name ) |
|
| 63 | + ); |
|
| 64 | + if ( ! isset( $data ) ) { |
|
| 65 | + return null; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + return $data['path']; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Load all of the files in the filemap. |
|
| 73 | + */ |
|
| 74 | + public function load_filemap() { |
|
| 75 | + if ( empty( $this->filemap ) ) { |
|
| 76 | + return; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + foreach ( $this->filemap as $file_identifier => $file_data ) { |
|
| 80 | + if ( empty( $GLOBALS['__composer_autoload_files'][ $file_identifier ] ) ) { |
|
| 81 | + require_once $file_data['path']; |
|
| 82 | + |
|
| 83 | + $GLOBALS['__composer_autoload_files'][ $file_identifier ] = true; |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Compares different class sources and returns the newest. |
|
| 90 | + * |
|
| 91 | + * @param array|null $classmap_data The classmap class data. |
|
| 92 | + * @param array|null $psr4_data The PSR-4 class data. |
|
| 93 | + * |
|
| 94 | + * @return array|null $data |
|
| 95 | + */ |
|
| 96 | + private function select_newest_file( $classmap_data, $psr4_data ) { |
|
| 97 | + if ( ! isset( $classmap_data ) ) { |
|
| 98 | + return $psr4_data; |
|
| 99 | + } elseif ( ! isset( $psr4_data ) ) { |
|
| 100 | + return $classmap_data; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + if ( $this->version_selector->is_version_update_required( $classmap_data['version'], $psr4_data['version'] ) ) { |
|
| 104 | + return $psr4_data; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return $classmap_data; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Finds the file for a given class in a PSR-4 namespace. |
|
| 112 | + * |
|
| 113 | + * @param string $class_name The class to find. |
|
| 114 | + * |
|
| 115 | + * @return array|null $data The version and path path to the file if found, null otherwise. |
|
| 116 | + */ |
|
| 117 | + private function find_psr4_file( $class_name ) { |
|
| 118 | + if ( ! isset( $this->psr4_map ) ) { |
|
| 119 | + return null; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // Don't bother with classes that have no namespace. |
|
| 123 | + $class_index = strrpos( $class_name, '\\' ); |
|
| 124 | + if ( ! $class_index ) { |
|
| 125 | + return null; |
|
| 126 | + } |
|
| 127 | + $class_for_path = str_replace( '\\', '/', $class_name ); |
|
| 128 | + |
|
| 129 | + // Search for the namespace by iteratively cutting off the last segment until |
|
| 130 | + // we find a match. This allows us to check the most-specific namespaces |
|
| 131 | + // first as well as minimize the amount of time spent looking. |
|
| 132 | + for ( |
|
| 133 | + $class_namespace = substr( $class_name, 0, $class_index ); |
|
| 134 | + ! empty( $class_namespace ); |
|
| 135 | + $class_namespace = substr( $class_namespace, 0, strrpos( $class_namespace, '\\' ) ) |
|
| 136 | + ) { |
|
| 137 | + $namespace = $class_namespace . '\\'; |
|
| 138 | + if ( ! isset( $this->psr4_map[ $namespace ] ) ) { |
|
| 139 | + continue; |
|
| 140 | + } |
|
| 141 | + $data = $this->psr4_map[ $namespace ]; |
|
| 142 | + |
|
| 143 | + foreach ( $data['path'] as $path ) { |
|
| 144 | + $path .= '/' . substr( $class_for_path, strlen( $namespace ) ) . '.php'; |
|
| 145 | + if ( file_exists( $path ) ) { |
|
| 146 | + return array( |
|
| 147 | + 'version' => $data['version'], |
|
| 148 | + 'path' => $path, |
|
| 149 | + ); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return null; |
|
| 155 | + } |
|
| 156 | 156 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @param array $psr4_map The versioned PSR-4 map to load using. |
| 43 | 43 | * @param array $filemap The versioned filemap to load. |
| 44 | 44 | */ |
| 45 | - public function __construct( $version_selector, $classmap, $psr4_map, $filemap ) { |
|
| 45 | + public function __construct($version_selector, $classmap, $psr4_map, $filemap) { |
|
| 46 | 46 | $this->version_selector = $version_selector; |
| 47 | 47 | $this->classmap = $classmap; |
| 48 | 48 | $this->psr4_map = $psr4_map; |
@@ -56,12 +56,12 @@ discard block |
||
| 56 | 56 | * |
| 57 | 57 | * @return string|null $file_path The path to the file if found, null if no class was found. |
| 58 | 58 | */ |
| 59 | - public function find_class_file( $class_name ) { |
|
| 59 | + public function find_class_file($class_name) { |
|
| 60 | 60 | $data = $this->select_newest_file( |
| 61 | - isset( $this->classmap[ $class_name ] ) ? $this->classmap[ $class_name ] : null, |
|
| 62 | - $this->find_psr4_file( $class_name ) |
|
| 61 | + isset($this->classmap[$class_name]) ? $this->classmap[$class_name] : null, |
|
| 62 | + $this->find_psr4_file($class_name) |
|
| 63 | 63 | ); |
| 64 | - if ( ! isset( $data ) ) { |
|
| 64 | + if (!isset($data)) { |
|
| 65 | 65 | return null; |
| 66 | 66 | } |
| 67 | 67 | |
@@ -72,15 +72,15 @@ discard block |
||
| 72 | 72 | * Load all of the files in the filemap. |
| 73 | 73 | */ |
| 74 | 74 | public function load_filemap() { |
| 75 | - if ( empty( $this->filemap ) ) { |
|
| 75 | + if (empty($this->filemap)) { |
|
| 76 | 76 | return; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - foreach ( $this->filemap as $file_identifier => $file_data ) { |
|
| 80 | - if ( empty( $GLOBALS['__composer_autoload_files'][ $file_identifier ] ) ) { |
|
| 79 | + foreach ($this->filemap as $file_identifier => $file_data) { |
|
| 80 | + if (empty($GLOBALS['__composer_autoload_files'][$file_identifier])) { |
|
| 81 | 81 | require_once $file_data['path']; |
| 82 | 82 | |
| 83 | - $GLOBALS['__composer_autoload_files'][ $file_identifier ] = true; |
|
| 83 | + $GLOBALS['__composer_autoload_files'][$file_identifier] = true; |
|
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | } |
@@ -93,14 +93,14 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | * @return array|null $data |
| 95 | 95 | */ |
| 96 | - private function select_newest_file( $classmap_data, $psr4_data ) { |
|
| 97 | - if ( ! isset( $classmap_data ) ) { |
|
| 96 | + private function select_newest_file($classmap_data, $psr4_data) { |
|
| 97 | + if (!isset($classmap_data)) { |
|
| 98 | 98 | return $psr4_data; |
| 99 | - } elseif ( ! isset( $psr4_data ) ) { |
|
| 99 | + } elseif (!isset($psr4_data)) { |
|
| 100 | 100 | return $classmap_data; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - if ( $this->version_selector->is_version_update_required( $classmap_data['version'], $psr4_data['version'] ) ) { |
|
| 103 | + if ($this->version_selector->is_version_update_required($classmap_data['version'], $psr4_data['version'])) { |
|
| 104 | 104 | return $psr4_data; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -114,35 +114,35 @@ discard block |
||
| 114 | 114 | * |
| 115 | 115 | * @return array|null $data The version and path path to the file if found, null otherwise. |
| 116 | 116 | */ |
| 117 | - private function find_psr4_file( $class_name ) { |
|
| 118 | - if ( ! isset( $this->psr4_map ) ) { |
|
| 117 | + private function find_psr4_file($class_name) { |
|
| 118 | + if (!isset($this->psr4_map)) { |
|
| 119 | 119 | return null; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // Don't bother with classes that have no namespace. |
| 123 | - $class_index = strrpos( $class_name, '\\' ); |
|
| 124 | - if ( ! $class_index ) { |
|
| 123 | + $class_index = strrpos($class_name, '\\'); |
|
| 124 | + if (!$class_index) { |
|
| 125 | 125 | return null; |
| 126 | 126 | } |
| 127 | - $class_for_path = str_replace( '\\', '/', $class_name ); |
|
| 127 | + $class_for_path = str_replace('\\', '/', $class_name); |
|
| 128 | 128 | |
| 129 | 129 | // Search for the namespace by iteratively cutting off the last segment until |
| 130 | 130 | // we find a match. This allows us to check the most-specific namespaces |
| 131 | 131 | // first as well as minimize the amount of time spent looking. |
| 132 | 132 | for ( |
| 133 | - $class_namespace = substr( $class_name, 0, $class_index ); |
|
| 134 | - ! empty( $class_namespace ); |
|
| 135 | - $class_namespace = substr( $class_namespace, 0, strrpos( $class_namespace, '\\' ) ) |
|
| 133 | + $class_namespace = substr($class_name, 0, $class_index); |
|
| 134 | + !empty($class_namespace); |
|
| 135 | + $class_namespace = substr($class_namespace, 0, strrpos($class_namespace, '\\')) |
|
| 136 | 136 | ) { |
| 137 | 137 | $namespace = $class_namespace . '\\'; |
| 138 | - if ( ! isset( $this->psr4_map[ $namespace ] ) ) { |
|
| 138 | + if (!isset($this->psr4_map[$namespace])) { |
|
| 139 | 139 | continue; |
| 140 | 140 | } |
| 141 | - $data = $this->psr4_map[ $namespace ]; |
|
| 141 | + $data = $this->psr4_map[$namespace]; |
|
| 142 | 142 | |
| 143 | - foreach ( $data['path'] as $path ) { |
|
| 144 | - $path .= '/' . substr( $class_for_path, strlen( $namespace ) ) . '.php'; |
|
| 145 | - if ( file_exists( $path ) ) { |
|
| 143 | + foreach ($data['path'] as $path) { |
|
| 144 | + $path .= '/' . substr($class_for_path, strlen($namespace)) . '.php'; |
|
| 145 | + if (file_exists($path)) { |
|
| 146 | 146 | return array( |
| 147 | 147 | 'version' => $data['version'], |
| 148 | 148 | 'path' => $path, |
@@ -6,73 +6,73 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class Latest_Autoloader_Guard { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * The Plugins_Handler instance. |
|
| 11 | - * |
|
| 12 | - * @var Plugins_Handler |
|
| 13 | - */ |
|
| 14 | - private $plugins_handler; |
|
| 9 | + /** |
|
| 10 | + * The Plugins_Handler instance. |
|
| 11 | + * |
|
| 12 | + * @var Plugins_Handler |
|
| 13 | + */ |
|
| 14 | + private $plugins_handler; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * The Autoloader_Handler instance. |
|
| 18 | - * |
|
| 19 | - * @var Autoloader_Handler |
|
| 20 | - */ |
|
| 21 | - private $autoloader_handler; |
|
| 16 | + /** |
|
| 17 | + * The Autoloader_Handler instance. |
|
| 18 | + * |
|
| 19 | + * @var Autoloader_Handler |
|
| 20 | + */ |
|
| 21 | + private $autoloader_handler; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * The Autoloader_locator instance. |
|
| 25 | - * |
|
| 26 | - * @var Autoloader_Locator |
|
| 27 | - */ |
|
| 28 | - private $autoloader_locator; |
|
| 23 | + /** |
|
| 24 | + * The Autoloader_locator instance. |
|
| 25 | + * |
|
| 26 | + * @var Autoloader_Locator |
|
| 27 | + */ |
|
| 28 | + private $autoloader_locator; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * The constructor. |
|
| 32 | - * |
|
| 33 | - * @param Plugins_Handler $plugins_handler The Plugins_Handler instance. |
|
| 34 | - * @param Autoloader_Handler $autoloader_handler The Autoloader_Handler instance. |
|
| 35 | - * @param Autoloader_Locator $autoloader_locator The Autoloader_Locator instance. |
|
| 36 | - */ |
|
| 37 | - public function __construct( $plugins_handler, $autoloader_handler, $autoloader_locator ) { |
|
| 38 | - $this->plugins_handler = $plugins_handler; |
|
| 39 | - $this->autoloader_handler = $autoloader_handler; |
|
| 40 | - $this->autoloader_locator = $autoloader_locator; |
|
| 41 | - } |
|
| 30 | + /** |
|
| 31 | + * The constructor. |
|
| 32 | + * |
|
| 33 | + * @param Plugins_Handler $plugins_handler The Plugins_Handler instance. |
|
| 34 | + * @param Autoloader_Handler $autoloader_handler The Autoloader_Handler instance. |
|
| 35 | + * @param Autoloader_Locator $autoloader_locator The Autoloader_Locator instance. |
|
| 36 | + */ |
|
| 37 | + public function __construct( $plugins_handler, $autoloader_handler, $autoloader_locator ) { |
|
| 38 | + $this->plugins_handler = $plugins_handler; |
|
| 39 | + $this->autoloader_handler = $autoloader_handler; |
|
| 40 | + $this->autoloader_locator = $autoloader_locator; |
|
| 41 | + } |
|
| 42 | 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; |
|
| 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 | 56 | |
| 57 | - // We need to reset the autoloader when the plugins change because |
|
| 58 | - // that means the autoloader was generated with a different list. |
|
| 59 | - if ( $this->plugins_handler->have_plugins_changed( $plugins ) ) { |
|
| 60 | - $this->autoloader_handler->reset_autoloader(); |
|
| 61 | - } |
|
| 57 | + // We need to reset the autoloader when the plugins change because |
|
| 58 | + // that means the autoloader was generated with a different list. |
|
| 59 | + if ( $this->plugins_handler->have_plugins_changed( $plugins ) ) { |
|
| 60 | + $this->autoloader_handler->reset_autoloader(); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - // When the latest autoloader has already been found we don't need to search for it again. |
|
| 64 | - // We should take care however because this will also trigger if the autoloader has been |
|
| 65 | - // included by an older one. |
|
| 66 | - if ( isset( $jetpack_autoloader_latest_version ) && ! $was_included_by_autoloader ) { |
|
| 67 | - return true; |
|
| 68 | - } |
|
| 63 | + // When the latest autoloader has already been found we don't need to search for it again. |
|
| 64 | + // We should take care however because this will also trigger if the autoloader has been |
|
| 65 | + // included by an older one. |
|
| 66 | + if ( isset( $jetpack_autoloader_latest_version ) && ! $was_included_by_autoloader ) { |
|
| 67 | + return true; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - $latest_plugin = $this->autoloader_locator->find_latest_autoloader( $plugins, $jetpack_autoloader_latest_version ); |
|
| 71 | - if ( isset( $latest_plugin ) && $latest_plugin !== $current_plugin ) { |
|
| 72 | - require $this->autoloader_locator->get_autoloader_path( $latest_plugin ); |
|
| 73 | - return true; |
|
| 74 | - } |
|
| 70 | + $latest_plugin = $this->autoloader_locator->find_latest_autoloader( $plugins, $jetpack_autoloader_latest_version ); |
|
| 71 | + if ( isset( $latest_plugin ) && $latest_plugin !== $current_plugin ) { |
|
| 72 | + require $this->autoloader_locator->get_autoloader_path( $latest_plugin ); |
|
| 73 | + return true; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return false; |
|
| 77 | - } |
|
| 76 | + return false; |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @param Autoloader_Handler $autoloader_handler The Autoloader_Handler instance. |
| 35 | 35 | * @param Autoloader_Locator $autoloader_locator The Autoloader_Locator instance. |
| 36 | 36 | */ |
| 37 | - public function __construct( $plugins_handler, $autoloader_handler, $autoloader_locator ) { |
|
| 37 | + public function __construct($plugins_handler, $autoloader_handler, $autoloader_locator) { |
|
| 38 | 38 | $this->plugins_handler = $plugins_handler; |
| 39 | 39 | $this->autoloader_handler = $autoloader_handler; |
| 40 | 40 | $this->autoloader_locator = $autoloader_locator; |
@@ -51,25 +51,25 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @return bool True if we should stop initialization, otherwise false. |
| 53 | 53 | */ |
| 54 | - public function should_stop_init( $current_plugin, $plugins, $was_included_by_autoloader ) { |
|
| 54 | + public function should_stop_init($current_plugin, $plugins, $was_included_by_autoloader) { |
|
| 55 | 55 | global $jetpack_autoloader_latest_version; |
| 56 | 56 | |
| 57 | 57 | // We need to reset the autoloader when the plugins change because |
| 58 | 58 | // that means the autoloader was generated with a different list. |
| 59 | - if ( $this->plugins_handler->have_plugins_changed( $plugins ) ) { |
|
| 59 | + if ($this->plugins_handler->have_plugins_changed($plugins)) { |
|
| 60 | 60 | $this->autoloader_handler->reset_autoloader(); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // When the latest autoloader has already been found we don't need to search for it again. |
| 64 | 64 | // We should take care however because this will also trigger if the autoloader has been |
| 65 | 65 | // included by an older one. |
| 66 | - if ( isset( $jetpack_autoloader_latest_version ) && ! $was_included_by_autoloader ) { |
|
| 66 | + if (isset($jetpack_autoloader_latest_version) && !$was_included_by_autoloader) { |
|
| 67 | 67 | return true; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - $latest_plugin = $this->autoloader_locator->find_latest_autoloader( $plugins, $jetpack_autoloader_latest_version ); |
|
| 71 | - if ( isset( $latest_plugin ) && $latest_plugin !== $current_plugin ) { |
|
| 72 | - require $this->autoloader_locator->get_autoloader_path( $latest_plugin ); |
|
| 70 | + $latest_plugin = $this->autoloader_locator->find_latest_autoloader($plugins, $jetpack_autoloader_latest_version); |
|
| 71 | + if (isset($latest_plugin) && $latest_plugin !== $current_plugin) { |
|
| 72 | + require $this->autoloader_locator->get_autoloader_path($latest_plugin); |
|
| 73 | 73 | return true; |
| 74 | 74 | } |
| 75 | 75 | |