AutoloadFileWriter.php
1 year ago
AutoloadGenerator.php
1 year ago
AutoloadProcessor.php
1 year ago
CustomAutoloaderPlugin.php
1 year ago
ManifestGenerator.php
1 year ago
autoload.php
5 years ago
class-autoloader-handler.php
5 years ago
class-autoloader-locator.php
1 year ago
class-autoloader.php
1 year ago
class-container.php
5 years ago
class-hook-manager.php
5 years ago
class-latest-autoloader-guard.php
1 year ago
class-manifest-reader.php
5 years ago
class-path-processor.php
1 year ago
class-php-autoloader.php
1 year ago
class-plugin-locator.php
1 year ago
class-plugins-handler.php
5 years ago
class-shutdown-handler.php
5 years ago
class-version-loader.php
1 year ago
class-version-selector.php
3 years ago
class-manifest-reader.php
92 lines
| 1 | <?php |
| 2 | /* HEADER */ // phpcs:ignore |
| 3 | |
| 4 | /** |
| 5 | * This class reads autoloader manifest files. |
| 6 | */ |
| 7 | class Manifest_Reader { |
| 8 | |
| 9 | /** |
| 10 | * The Version_Selector object. |
| 11 | * |
| 12 | * @var Version_Selector |
| 13 | */ |
| 14 | private $version_selector; |
| 15 | |
| 16 | /** |
| 17 | * The constructor. |
| 18 | * |
| 19 | * @param Version_Selector $version_selector The Version_Selector object. |
| 20 | */ |
| 21 | public function __construct( $version_selector ) { |
| 22 | $this->version_selector = $version_selector; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Reads all of the manifests in the given plugin paths. |
| 27 | * |
| 28 | * @param array $plugin_paths The paths to the plugins we're loading the manifest in. |
| 29 | * @param string $manifest_path The path that we're loading the manifest from in each plugin. |
| 30 | * @param array $path_map The path map to add the contents of the manifests to. |
| 31 | * |
| 32 | * @return array $path_map The path map we've built using the manifests in each plugin. |
| 33 | */ |
| 34 | public function read_manifests( $plugin_paths, $manifest_path, &$path_map ) { |
| 35 | $file_paths = array_map( |
| 36 | function ( $path ) use ( $manifest_path ) { |
| 37 | return trailingslashit( $path ) . $manifest_path; |
| 38 | }, |
| 39 | $plugin_paths |
| 40 | ); |
| 41 | |
| 42 | foreach ( $file_paths as $path ) { |
| 43 | $this->register_manifest( $path, $path_map ); |
| 44 | } |
| 45 | |
| 46 | return $path_map; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Registers a plugin's manifest file with the path map. |
| 51 | * |
| 52 | * @param string $manifest_path The absolute path to the manifest that we're loading. |
| 53 | * @param array $path_map The path map to add the contents of the manifest to. |
| 54 | */ |
| 55 | protected function register_manifest( $manifest_path, &$path_map ) { |
| 56 | if ( ! is_readable( $manifest_path ) ) { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | $manifest = require $manifest_path; |
| 61 | if ( ! is_array( $manifest ) ) { |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | foreach ( $manifest as $key => $data ) { |
| 66 | $this->register_record( $key, $data, $path_map ); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Registers an entry from the manifest in the path map. |
| 72 | * |
| 73 | * @param string $key The identifier for the entry we're registering. |
| 74 | * @param array $data The data for the entry we're registering. |
| 75 | * @param array $path_map The path map to add the contents of the manifest to. |
| 76 | */ |
| 77 | protected function register_record( $key, $data, &$path_map ) { |
| 78 | if ( isset( $path_map[ $key ]['version'] ) ) { |
| 79 | $selected_version = $path_map[ $key ]['version']; |
| 80 | } else { |
| 81 | $selected_version = null; |
| 82 | } |
| 83 | |
| 84 | if ( $this->version_selector->is_version_update_required( $selected_version, $data['version'] ) ) { |
| 85 | $path_map[ $key ] = array( |
| 86 | 'version' => $data['version'], |
| 87 | 'path' => $data['path'], |
| 88 | ); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 |