1 | <?php |
||
7 | class Version_Loader { |
||
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 ) { |
||
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 ) { |
||
70 | |||
71 | /** |
||
72 | * Load all of the files in the filemap. |
||
73 | */ |
||
74 | public function load_filemap() { |
||
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 ) { |
||
156 | } |
||
157 |