Brak opisu

class-manifest-reader.php 2.6KB

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