diff --git a/src/dashboard/application/configuration/dashboard-configuration.php b/src/dashboard/application/configuration/dashboard-configuration.php index c9eb9fef674..eae738da4a0 100644 --- a/src/dashboard/application/configuration/dashboard-configuration.php +++ b/src/dashboard/application/configuration/dashboard-configuration.php @@ -5,6 +5,8 @@ namespace Yoast\WP\SEO\Dashboard\Application\Configuration; use Yoast\WP\SEO\Dashboard\Application\Content_Types\Content_Types_Repository; +use Yoast\WP\SEO\Dashboard\Application\Endpoints\Endpoints_Repository; +use Yoast\WP\SEO\Dashboard\Infrastructure\Nonces\Nonce_Repository; use Yoast\WP\SEO\Editors\Application\Analysis_Features\Enabled_Analysis_Features_Repository; use Yoast\WP\SEO\Editors\Framework\Keyphrase_Analysis; use Yoast\WP\SEO\Editors\Framework\Readability_Analysis; @@ -44,6 +46,20 @@ class Dashboard_Configuration { */ private $enabled_analysis_features_repository; + /** + * The endpoints repository. + * + * @var Endpoints_Repository + */ + private $endpoints_repository; + + /** + * The nonce repository. + * + * @var Nonce_Repository + */ + private $nonce_repository; + /** * The constructor. * @@ -53,17 +69,23 @@ class Dashboard_Configuration { * @param User_Helper $user_helper The user helper. * @param Enabled_Analysis_Features_Repository $enabled_analysis_features_repository The analysis feature * repository. + * @param Endpoints_Repository $endpoints_repository The endpoints repository. + * @param Nonce_Repository $nonce_repository The nonce repository. */ public function __construct( Content_Types_Repository $content_types_repository, Indexable_Helper $indexable_helper, User_Helper $user_helper, - Enabled_Analysis_Features_Repository $enabled_analysis_features_repository + Enabled_Analysis_Features_Repository $enabled_analysis_features_repository, + Endpoints_Repository $endpoints_repository, + Nonce_Repository $nonce_repository ) { $this->content_types_repository = $content_types_repository; $this->indexable_helper = $indexable_helper; $this->user_helper = $user_helper; $this->enabled_analysis_features_repository = $enabled_analysis_features_repository; + $this->endpoints_repository = $endpoints_repository; + $this->nonce_repository = $nonce_repository; } /** @@ -82,6 +104,8 @@ public function get_configuration(): array { Keyphrase_Analysis::NAME, ] )->to_array(), + 'endpoints' => $this->endpoints_repository->get_all_endpoints()->to_array(), + 'nonce' => $this->nonce_repository->get_rest_nonce(), ]; } } diff --git a/src/dashboard/application/endpoints/endpoints-repository.php b/src/dashboard/application/endpoints/endpoints-repository.php new file mode 100644 index 00000000000..d293197a559 --- /dev/null +++ b/src/dashboard/application/endpoints/endpoints-repository.php @@ -0,0 +1,42 @@ + + */ + private $endpoints; + + /** + * Constructs the repository. + * + * @param Endpoint_Interface ...$endpoints The endpoints to add to the repository. + */ + public function __construct( Endpoint_Interface ...$endpoints ) { + $this->endpoints = $endpoints; + } + + /** + * Creates a list with all endpoints. + * + * @return Endpoint_List The list with all endpoints. + */ + public function get_all_endpoints(): Endpoint_List { + $list = new Endpoint_List(); + foreach ( $this->endpoints as $endpoint ) { + $list->add_endpoint( $endpoint ); + } + + return $list; + } +} diff --git a/src/dashboard/domain/endpoint/endpoint-interface.php b/src/dashboard/domain/endpoint/endpoint-interface.php new file mode 100644 index 00000000000..ae99c2667e9 --- /dev/null +++ b/src/dashboard/domain/endpoint/endpoint-interface.php @@ -0,0 +1,34 @@ + $endpoints + */ + 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 The array of endpoints. + */ + public function to_array(): array { + $result = []; + foreach ( $this->endpoints as $endpoint ) { + $result[ $endpoint->get_name() ] = $endpoint->get_url(); + } + + return $result; + } +} diff --git a/src/dashboard/infrastructure/endpoints/readability-scores-endpoint.php b/src/dashboard/infrastructure/endpoints/readability-scores-endpoint.php new file mode 100644 index 00000000000..387162ea3d0 --- /dev/null +++ b/src/dashboard/infrastructure/endpoints/readability-scores-endpoint.php @@ -0,0 +1,48 @@ +get_namespace() . $this->get_route() ); + } +} diff --git a/src/dashboard/infrastructure/endpoints/seo-scores-endpoint.php b/src/dashboard/infrastructure/endpoints/seo-scores-endpoint.php new file mode 100644 index 00000000000..ae129ab562b --- /dev/null +++ b/src/dashboard/infrastructure/endpoints/seo-scores-endpoint.php @@ -0,0 +1,48 @@ +get_namespace() . $this->get_route() ); + } +} diff --git a/src/dashboard/infrastructure/nonces/nonce-repository.php b/src/dashboard/infrastructure/nonces/nonce-repository.php new file mode 100644 index 00000000000..162fe086e3a --- /dev/null +++ b/src/dashboard/infrastructure/nonces/nonce-repository.php @@ -0,0 +1,18 @@ +get_route_prefix(), [ [