Yoast\WP\SEO\Routes\Endpoint

Endpoint_List{} │ Yoast 1.0

List of endpoints.

Хуков нет.

Использование

$Endpoint_List = new Endpoint_List();
// use class methods

Методы

  1. public add_endpoint( Endpoint_Interface $endpoint )
  2. public merge_with( Endpoint_List $other_list )
  3. public to_array()
  4. public paths (namespace + route, without host)
  5. public to_paths_array()
  6. ERROR: no method name found on line `*`

Код Endpoint_List{} Yoast 28.9

class Endpoint_List {

	/**
	 * Holds the endpoints.
	 *
	 * @var array<Endpoint_Interface>
	 */
	private $endpoints = [];

	/**
	 * Adds an endpoint to the list.
	 *
	 * @param Endpoint_Interface $endpoint An endpoint.
	 *
	 * @return void
	 */
	public function add_endpoint( Endpoint_Interface $endpoint ): void {
		$this->endpoints[] = $endpoint;
	}

	/**
	 * Converts the list to an array.
	 *
	 * @return array<string, string> The array of endpoints.
	 */
	public function to_array(): array {
		$result = [];
		foreach ( $this->endpoints as $endpoint ) {
			$result[ $endpoint->get_name() ] = $endpoint->get_url();
		}

		return $result;
	}

	/**
	 * Converts the list to an array of paths (namespace + route, without host).
	 *
	 * @return array<string, string> The array of endpoint paths.
	 */
	public function to_paths_array(): array {
		$result = [];
		foreach ( $this->endpoints as $endpoint ) {
			$result[ $endpoint->get_name() ] = $endpoint->get_namespace() . $endpoint->get_route();
		}

		return $result;
	}

	/**
	 * Merges two Endpoint_List objects together.
	 * Returns the current instance for method chaining.
	 *
	 * @param Endpoint_List $other_list The other Endpoint_List to merge with.
	 *
	 * @return $this
	 */
	public function merge_with( Endpoint_List $other_list ): Endpoint_List {
		foreach ( $other_list->endpoints as $endpoint ) {
			$this->add_endpoint( $endpoint );
		}

		return $this;
	}
}