@@ 1630-1663 (lines=34) @@ | ||
1627 | * |
|
1628 | * @return array Array of endpoint paths, min_versions and max_versions, keyed by last segment of path |
|
1629 | **/ |
|
1630 | protected function get_endpoint_path_versions() { |
|
1631 | ||
1632 | static $cache_result; |
|
1633 | ||
1634 | if ( ! empty ( $cache_result ) ) { |
|
1635 | return $cache_result; |
|
1636 | } |
|
1637 | ||
1638 | /* |
|
1639 | * Create a map of endpoints and their min/max versions keyed by the last segment of the path (e.g. 'posts') |
|
1640 | * This reduces the search space when finding endpoint matches in get_closest_version_of_endpoint() |
|
1641 | */ |
|
1642 | $endpoint_path_versions = array(); |
|
1643 | ||
1644 | foreach ( $this->api->endpoints as $key => $endpoint_objects ) { |
|
1645 | ||
1646 | // The key contains a serialized path, min_version and max_version |
|
1647 | list( $path, $min_version, $max_version ) = unserialize( $key ); |
|
1648 | ||
1649 | // Grab the last component of the relative path to use as the top-level key |
|
1650 | $last_path_segment = $this->get_last_segment_of_relative_path( $path ); |
|
1651 | ||
1652 | $endpoint_path_versions[ $last_path_segment ][] = array( |
|
1653 | 'path' => $path, |
|
1654 | 'min_version' => $min_version, |
|
1655 | 'max_version' => $max_version, |
|
1656 | 'request_methods' => array_keys( $endpoint_objects ) |
|
1657 | ); |
|
1658 | } |
|
1659 | ||
1660 | $cache_result = $endpoint_path_versions; |
|
1661 | ||
1662 | return $endpoint_path_versions; |
|
1663 | } |
|
1664 | ||
1665 | /** |
|
1666 | * Grab the last segment of a relative path |
@@ 213-246 (lines=34) @@ | ||
210 | * |
|
211 | * @return array Array of endpoint paths, min_versions and max_versions, keyed by last segment of path |
|
212 | **/ |
|
213 | protected function get_endpoint_path_versions() { |
|
214 | ||
215 | static $cache_result; |
|
216 | ||
217 | if ( ! empty ( $cache_result ) ) { |
|
218 | return $cache_result; |
|
219 | } |
|
220 | ||
221 | /* |
|
222 | * Create a map of endpoints and their min/max versions keyed by the last segment of the path (e.g. 'posts') |
|
223 | * This reduces the search space when finding endpoint matches in get_closest_version_of_endpoint() |
|
224 | */ |
|
225 | $endpoint_path_versions = array(); |
|
226 | ||
227 | foreach ( $this->api->endpoints as $key => $endpoint_objects ) { |
|
228 | ||
229 | // The key contains a serialized path, min_version and max_version |
|
230 | list( $path, $min_version, $max_version ) = unserialize( $key ); |
|
231 | ||
232 | // Grab the last component of the relative path to use as the top-level key |
|
233 | $last_path_segment = $this->get_last_segment_of_relative_path( $path ); |
|
234 | ||
235 | $endpoint_path_versions[ $last_path_segment ][] = array( |
|
236 | 'path' => $path, |
|
237 | 'min_version' => $min_version, |
|
238 | 'max_version' => $max_version, |
|
239 | 'request_methods' => array_keys( $endpoint_objects ) |
|
240 | ); |
|
241 | } |
|
242 | ||
243 | $cache_result = $endpoint_path_versions; |
|
244 | ||
245 | return $endpoint_path_versions; |
|
246 | } |
|
247 | ||
248 | /** |
|
249 | * Grab the last segment of a relative path |