PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.6
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / routes / endpoint / endpoint-list.php

endpoint-list.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.6, at src/routes/endpoint/endpoint-list.php

73 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded
4 namespace Yoast\WP\SEO\Routes\Endpoint;
5
6 /**
7 * List of endpoints.
8 */
9 class Endpoint_List {
10
11 /**
12 * Holds the endpoints.
13 *
14 * @var array<Endpoint_Interface>
15 */
16 private $endpoints = [];
17
18 /**
19 * Adds an endpoint to the list.
20 *
21 * @param Endpoint_Interface $endpoint An endpoint.
22 *
23 * @return void
24 */
25 public function add_endpoint( Endpoint_Interface $endpoint ): void {
26 $this->endpoints[] = $endpoint;
27 }
28
29 /**
30 * Converts the list to an array.
31 *
32 * @return array<string, string> The array of endpoints.
33 */
34 public function to_array(): array {
35 $result = [];
36 foreach ( $this->endpoints as $endpoint ) {
37 $result[ $endpoint->get_name() ] = $endpoint->get_url();
38 }
39
40 return $result;
41 }
42
43 /**
44 * Converts the list to an array of paths (namespace + route, without host).
45 *
46 * @return array<string, string> The array of endpoint paths.
47 */
48 public function to_paths_array(): array {
49 $result = [];
50 foreach ( $this->endpoints as $endpoint ) {
51 $result[ $endpoint->get_name() ] = $endpoint->get_namespace() . $endpoint->get_route();
52 }
53
54 return $result;
55 }
56
57 /**
58 * Merges two Endpoint_List objects together.
59 * Returns the current instance for method chaining.
60 *
61 * @param Endpoint_List $other_list The other Endpoint_List to merge with.
62 *
63 * @return $this
64 */
65 public function merge_with( Endpoint_List $other_list ): Endpoint_List {
66 foreach ( $other_list->endpoints as $endpoint ) {
67 $this->add_endpoint( $endpoint );
68 }
69
70 return $this;
71 }
72 }
73