automattic
5 years ago
bin
5 years ago
composer
5 years ago
jetpack-autoloader
5 years ago
league
5 years ago
maxmind-db
5 years ago
pelago
6 years ago
psr
5 years ago
symfony
5 years ago
woocommerce
5 years ago
autoload.php
5 years ago
autoload_packages.php
5 years ago
class-autoloader-handler.php
5 years ago
class-classes-handler.php
5 years ago
class-files-handler.php
5 years ago
class-plugins-handler.php
5 years ago
class-version-selector.php
5 years ago
class-files-handler.php
113 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This file was automatically generated by automattic/jetpack-autoloader. |
| 4 | * |
| 5 | * @package automattic/jetpack-autoloader |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Autoloader\jp5e9090adb7e03a3eeba3759a946171f6; |
| 9 | |
| 10 | // phpcs:ignore |
| 11 | |
| 12 | /** |
| 13 | * This class selects the package versions for the package files. |
| 14 | */ |
| 15 | class Files_Handler { |
| 16 | |
| 17 | /** |
| 18 | * The Plugins_Handler object. |
| 19 | * |
| 20 | * @var Plugins_Handler |
| 21 | */ |
| 22 | private $plugins_handler = null; |
| 23 | |
| 24 | /** |
| 25 | * The Version_Selector object. |
| 26 | * |
| 27 | * @var Version_Selector |
| 28 | */ |
| 29 | private $version_selector = null; |
| 30 | |
| 31 | /** |
| 32 | * The constructor. |
| 33 | * |
| 34 | * @param Plugins_Handler $plugins_handler The Plugins_Handler object. |
| 35 | * @param Version_Selector $version_selector The Version_Selector object. |
| 36 | */ |
| 37 | public function __construct( $plugins_handler, $version_selector ) { |
| 38 | $this->plugins_handler = $plugins_handler; |
| 39 | $this->version_selector = $version_selector; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Adds the version of a package file to the $jetpack_packages_filemap global |
| 44 | * array so that we can load the most recent version. |
| 45 | * |
| 46 | * @param string $file_identifier Unique id to file assigned by composer based on package name and filename. |
| 47 | * @param string $version Version of the file. |
| 48 | * @param string $path Absolute path to the file so that we can load it. |
| 49 | */ |
| 50 | public function enqueue_package_file( $file_identifier, $version, $path ) { |
| 51 | global $jetpack_packages_filemap; |
| 52 | |
| 53 | if ( isset( $jetpack_packages_filemap[ $file_identifier ]['version'] ) ) { |
| 54 | $selected_version = $jetpack_packages_filemap[ $file_identifier ]['version']; |
| 55 | } else { |
| 56 | $selected_version = null; |
| 57 | } |
| 58 | |
| 59 | if ( $this->version_selector->is_version_update_required( $selected_version, $version ) ) { |
| 60 | $jetpack_packages_filemap[ $file_identifier ] = array( |
| 61 | 'version' => $version, |
| 62 | 'path' => $path, |
| 63 | ); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Creates a path to the plugin's filemap. The filemap filename is the filename |
| 69 | * generated by Jetpack Autoloader version >= 2.0. |
| 70 | * |
| 71 | * @param String $plugin_path The plugin path. |
| 72 | * |
| 73 | * @return String The filemap path |
| 74 | */ |
| 75 | public function create_filemap_path( $plugin_path ) { |
| 76 | return trailingslashit( $plugin_path ) . 'vendor/composer/jetpack_autoload_filemap.php'; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Initializes the filemap. |
| 81 | */ |
| 82 | public function set_file_paths() { |
| 83 | $active_plugin_paths = $this->plugins_handler->get_all_active_plugins_paths(); |
| 84 | $filemap_paths = array_map( array( $this, 'create_filemap_path' ), $active_plugin_paths ); |
| 85 | |
| 86 | foreach ( $filemap_paths as $path ) { |
| 87 | if ( is_readable( $path ) ) { |
| 88 | $file_map = require $path; |
| 89 | |
| 90 | if ( is_array( $file_map ) ) { |
| 91 | foreach ( $file_map as $file_identifier => $file_data ) { |
| 92 | $this->enqueue_package_file( $file_identifier, $file_data['version'], $file_data['path'] ); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Include latest version of all enqueued files. |
| 101 | */ |
| 102 | public function file_loader() { |
| 103 | global $jetpack_packages_filemap; |
| 104 | foreach ( $jetpack_packages_filemap as $file_identifier => $file_data ) { |
| 105 | if ( empty( $GLOBALS['__composer_autoload_files'][ $file_identifier ] ) ) { |
| 106 | require_once $file_data['path']; |
| 107 | |
| 108 | $GLOBALS['__composer_autoload_files'][ $file_identifier ] = true; |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 |