class-autoloader-handler.php
5 days ago
class-autoloader-locator.php
5 days ago
class-autoloader.php
5 days ago
class-container.php
5 days ago
class-hook-manager.php
5 days ago
class-latest-autoloader-guard.php
5 days ago
class-manifest-reader.php
5 days ago
class-path-processor.php
5 days ago
class-php-autoloader.php
5 days ago
class-plugin-locator.php
5 days ago
class-plugins-handler.php
5 days ago
class-shutdown-handler.php
5 days ago
class-version-loader.php
5 days ago
class-version-selector.php
5 days ago
index.php
11 months ago
class-version-loader.php
90 lines
| 1 | <?php |
| 2 | namespace Automattic\Jetpack\Autoloader\jp362475ab3000a6225facecf40e51a264\al5_0_8; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | // phpcs:ignore |
| 5 | class Version_Loader { |
| 6 | private $version_selector; |
| 7 | private $classmap; |
| 8 | private $psr4_map; |
| 9 | private $filemap; |
| 10 | public function __construct( $version_selector, $classmap, $psr4_map, $filemap ) { |
| 11 | $this->version_selector = $version_selector; |
| 12 | $this->classmap = $classmap; |
| 13 | $this->psr4_map = $psr4_map; |
| 14 | $this->filemap = $filemap; |
| 15 | } |
| 16 | public function get_class_map() { |
| 17 | return $this->classmap; |
| 18 | } |
| 19 | public function get_psr4_map() { |
| 20 | return $this->psr4_map; |
| 21 | } |
| 22 | public function find_class_file( $class_name ) { |
| 23 | $data = $this->select_newest_file( |
| 24 | $this->classmap[ $class_name ] ?? null, |
| 25 | $this->find_psr4_file( $class_name ) |
| 26 | ); |
| 27 | if ( ! isset( $data ) ) { |
| 28 | return null; |
| 29 | } |
| 30 | return $data['path']; |
| 31 | } |
| 32 | public function load_filemap() { |
| 33 | if ( empty( $this->filemap ) ) { |
| 34 | return; |
| 35 | } |
| 36 | foreach ( $this->filemap as $file_identifier => $file_data ) { |
| 37 | if ( empty( $GLOBALS['__composer_autoload_files'][ $file_identifier ] ) ) { |
| 38 | require_once $file_data['path']; |
| 39 | $GLOBALS['__composer_autoload_files'][ $file_identifier ] = true; |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | private function select_newest_file( $classmap_data, $psr4_data ) { |
| 44 | if ( ! isset( $classmap_data ) ) { |
| 45 | return $psr4_data; |
| 46 | } elseif ( ! isset( $psr4_data ) ) { |
| 47 | return $classmap_data; |
| 48 | } |
| 49 | if ( $this->version_selector->is_version_update_required( $classmap_data['version'], $psr4_data['version'] ) ) { |
| 50 | return $psr4_data; |
| 51 | } |
| 52 | return $classmap_data; |
| 53 | } |
| 54 | private function find_psr4_file( $class_name ) { |
| 55 | if ( empty( $this->psr4_map ) ) { |
| 56 | return null; |
| 57 | } |
| 58 | // Don't bother with classes that have no namespace. |
| 59 | $class_index = strrpos( $class_name, '\\' ); |
| 60 | if ( ! $class_index ) { |
| 61 | return null; |
| 62 | } |
| 63 | $class_for_path = str_replace( '\\', '/', $class_name ); |
| 64 | // Search for the namespace by iteratively cutting off the last segment until |
| 65 | // we find a match. This allows us to check the most-specific namespaces |
| 66 | // first as well as minimize the amount of time spent looking. |
| 67 | for ( |
| 68 | $class_namespace = substr( $class_name, 0, $class_index ); |
| 69 | ! empty( $class_namespace ); |
| 70 | $class_namespace = substr( $class_namespace, 0, strrpos( $class_namespace, '\\' ) ) |
| 71 | ) { |
| 72 | $namespace = $class_namespace . '\\'; |
| 73 | if ( ! isset( $this->psr4_map[ $namespace ] ) ) { |
| 74 | continue; |
| 75 | } |
| 76 | $data = $this->psr4_map[ $namespace ]; |
| 77 | foreach ( $data['path'] as $path ) { |
| 78 | $path .= '/' . substr( $class_for_path, strlen( $namespace ) ) . '.php'; |
| 79 | if ( file_exists( $path ) ) { |
| 80 | return array( |
| 81 | 'version' => $data['version'], |
| 82 | 'path' => $path, |
| 83 | ); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | return null; |
| 88 | } |
| 89 | } |
| 90 |