Passed
Pull Request — master (#240)
by
unknown
03:32
created

WPInv_API_Exception   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0
1
<?php
2
/**
3
 * Contains the main API class
4
 *
5
 * @since 1.0.0
6
 * @package Invoicing
7
 */
8
 
9
// MUST have WordPress.
10
if ( !defined( 'WPINC' ) ) {
11
    exit;
12
}
13
14
/**
15
 * The main API class
16
 */
17
class WPInv_API {
18
19
    /**
20
     * @param string A prefix for our REST routes
21
     */
22
    public $api_namespace    = '';
23
24
    /**
25
     * @param WPInv_REST_Invoice_Controller Invoices controller
26
     */
27
    public $invoices_controller;
28
    
29
    /**
30
     * Class constructor. 
31
     * 
32
     * @since 1.0.13
33
     * Sets the API namespace and inits hooks
34
     */
35
    public function __construct( $api_namespace = 'invoicing/v1' ) {
36
37
        // Include controllers and related files
38
        $this->includes();
39
40
        // Set up class variables
41
        $this->api_namespace       = apply_filters( 'wpinv_rest_api_namespace', $api_namespace );
42
        $this->invoices_controller = new WPInv_REST_Invoice_Controller( $this->api_namespace );
43
44
        //Register REST routes
45
        add_action( 'rest_api_init', array( $this, 'register_rest_routes' ) );
46
    }
47
48
49
	/**
50
	 * Registers routes
51
	 *
52
     * @since 1.0.13
53
	 */
54
	public function register_rest_routes() {
55
56
		//Invoices
57
		$this->invoices_controller->register_routes();
58
        
59
    }
60
61
62
    /**
63
     * Loads API files and controllers
64
     * 
65
     *  @return void
66
     */
67
    protected function includes() {
68
        
69
        // Invoices
70
        require_once( WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-invoice-controller.php' );
71
72
    }
73
    
74
75
}