PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.2.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.2.0
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
solid-performance / src / Performance / API / Provider.php

Provider.php in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution 1.2.0, at src/Performance/API/Provider.php

92 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The provider responsible for registering API classes with the container & WordPress.
4 *
5 * @since 0.1.0
6 *
7 * @package SolidWP\Performance
8 */
9
10 namespace SolidWP\Performance\API;
11
12 use SolidWP\Performance\API\Routes\Page_Cache\Clear;
13 use SolidWP\Performance\API\Routes\Page_Cache\Debug;
14 use SolidWP\Performance\API\Routes\Page_Cache\Off;
15 use SolidWP\Performance\API\Routes\Page_Cache\On;
16 use SolidWP\Performance\API\Routes\Page_Cache\Status;
17 use SolidWP\Performance\API\Routes\Page_Cache\Regenerate;
18 use SolidWP\Performance\Contracts\Service_Provider;
19
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit;
22 }
23
24 /**
25 * The provider responsible for registering API classes with the container & WordPress.
26 *
27 * @since 0.1.0
28 *
29 * @package SolidWP\Performance
30 */
31 class Provider extends Service_Provider {
32
33 /**
34 * The namespace of the plugin's REST API routes.
35 *
36 * @since 0.1.0
37 *
38 * @var string
39 */
40 private string $namespace = 'solid-performance/v1';
41
42 /**
43 * All the endpoints that should be registered with the REST API.
44 *
45 * @since 0.1.0
46 *
47 * @var array<int,string>
48 */
49 private array $endpoints = [
50 Clear::class,
51 Debug::class,
52 Off::class,
53 On::class,
54 Regenerate::class,
55 Status::class,
56 ];
57
58 /**
59 * {@inheritdoc}
60 */
61 public function register(): void {
62 add_action( 'rest_api_init', [ $this, 'register_all_endpoints' ] );
63 }
64
65 /**
66 * Registers all endpoints of the REST API.
67 *
68 * @since 0.1.0
69 *
70 * @return void
71 */
72 public function register_all_endpoints(): void {
73 foreach ( $this->endpoints as $class ) {
74 /** @var Route */
75 $endpoint = $this->container->get( $class );
76 register_rest_route(
77 $this->namespace,
78 $endpoint->get_path(),
79 [
80 [
81 'methods' => $endpoint->get_methods(),
82 'callback' => [ $endpoint, 'callback' ],
83 'args' => $endpoint->get_arguments(),
84 'permission_callback' => [ $endpoint, 'permission_callback' ],
85 ],
86 'schema' => [ $endpoint, 'schema_callback' ],
87 ],
88 );
89 }
90 }
91 }
92