Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Endpoints
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 init
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 register_routes
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Registers the REST routes behind Settings > Sharing.
4 *
5 * @package automattic/jetpack-sharing-likes
6 */
7
8declare( strict_types = 1 );
9
10namespace Automattic\Jetpack\Sharing_Likes\REST;
11
12/**
13 * The routes the settings screen reads and saves through, on every platform.
14 *
15 * `wpcom/v2` because on WordPress.com Simple, wp-admin `apiFetch` goes through public-api,
16 * which serves only a fixed set of namespaces: `jetpack/v4` or our own would 404 there.
17 */
18final class Endpoints {
19
20    /**
21     * REST namespace.
22     */
23    public const REST_NAMESPACE = 'wpcom/v2';
24
25    /**
26     * Prefix every route shares.
27     */
28    public const BASE = 'sharing-likes';
29
30    /**
31     * Register the routes when the REST server starts.
32     *
33     * Callers must not gate this on module state or options: on Simple the routes
34     * register before public-api switches to the requested site.
35     */
36    public static function init(): void {
37        add_action( 'rest_api_init', array( __CLASS__, 'register_routes' ) );
38    }
39
40    /**
41     * Register every route.
42     */
43    public static function register_routes(): void {
44        ( new Settings_Controller() )->register_routes();
45        ( new Status_Controller() )->register_routes();
46        ( new Services_Controller() )->register_routes();
47    }
48}