-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass-server.php
76 lines (64 loc) · 1.77 KB
/
class-server.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Initialize this version of the REST API.
*
* @package RFQ\RestApi
*/
namespace Addify\Request_a_Quote\RestApi;
defined( 'ABSPATH' ) || exit;
/**
* Class responsible for loading the REST API and all REST API namespaces.
*/
use Automattic\WooCommerce\RestApi\Utilities\SingletonTrait;
class Server {
use SingletonTrait;
/**
* REST API namespaces and endpoints.
*
* @var array
*/
protected $controllers = array();
/**
* Hook into WordPress ready to init the REST API as needed.
*/
public function init() {
add_action( 'rest_api_init', array( $this, 'register_rest_routes' ), 10 );
}
/**
* Register REST API routes.
*/
public function register_rest_routes() {
require AFRFQ_PLUGIN_DIR . 'includes/rest-api/controllers/class-af-r-f-q-rest-rules-controller.php';
require AFRFQ_PLUGIN_DIR . 'includes/rest-api/controllers/class-af-r-f-q-rest-quotes-controller.php';
foreach ( $this->get_rest_namespaces() as $namespace => $controllers ) {
foreach ( $controllers as $controller_name => $controller_class ) {
$this->controllers[ $namespace ][ $controller_name ] = new $controller_class();
$this->controllers[ $namespace ][ $controller_name ]->register_routes();
}
}
}
/**
* Get API namespaces - new namespaces should be registered here.
*
* @return array List of Namespaces and Main controller classes.
*/
protected function get_rest_namespaces() {
return apply_filters(
'addify_rfq_rest_api_get_rest_namespaces',
array(
'afrfq' => $this->get_controllers(),
)
);
}
/**
* List of controllers in the namespace.
*
* @return array
*/
protected function get_controllers() {
return array(
'rfq_rules' => 'AF_R_F_Q_Rest_Rules_Controller',
'rfq_quotes' => 'AF_R_F_Q_Rest_Quotes_Controller',
);
}
}