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
RestApi
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
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
2
1<?php
2
3namespace NewfoldLabs\WP\Module\Installer\RestApi;
4
5/**
6 * Instantiate controllers and register routes.
7 */
8final class RestApi {
9
10    /**
11     * List of controllers to register.
12     *
13     * @var array
14     */
15    protected $controllers = array(
16        'NewfoldLabs\\WP\\Module\\Installer\\RestApi\\PluginsController',
17        'NewfoldLabs\\WP\\Module\\Installer\\RestApi\\ThemeInstallerController',
18    );
19
20    /**
21     * The constructor that registers all the controllers.
22     */
23    public function __construct() {
24        add_action( 'rest_api_init', array( $this, 'register_routes' ) );
25    }
26
27    /**
28     * Helper to register all the controller.
29     *
30     * @return void
31     */
32    public function register_routes() {
33        foreach ( $this->controllers as $controller ) {
34            /**
35             * Get an instance of the WP_REST_Controller.
36             *
37             * @var $instance WP_REST_Controller
38             */
39            $instance = new $controller();
40            $instance->register_routes();
41        }
42    }
43}