| @@ -1,59 +1,59 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Initialize this version of the REST API. | |
| 4 | - * | |
| 5 | - * @author Nhamdv <daonham95@gmail.com> | |
| 6 | - * @package LP/JWT/RestApi | |
| 7 | - */ | |
| 8 | -class LP_Jwt_RestApi { | |
| 9 | - | |
| 10 | - protected static $instance = null; | |
| 11 | - | |
| 12 | - protected $controllers = array(); | |
| 13 | - | |
| 14 | - public function init() { | |
| 15 | - add_action( 'rest_api_init', array( $this, 'register_rest_routes' ), 10 ); | |
| 16 | - } | |
| 17 | - | |
| 18 | - public function register_rest_routes() { | |
| 19 | - foreach ( $this->get_rest_namespaces() as $namespace => $controllers ) { | |
| 20 | - foreach ( $controllers as $controller_name => $controller_class ) { | |
| 21 | - $this->controllers[ $namespace ][ $controller_name ] = new $controller_class(); | |
| 22 | - $this->controllers[ $namespace ][ $controller_name ]->register_routes(); | |
| 23 | - } | |
| 24 | - } | |
| 25 | - } | |
| 26 | - | |
| 27 | - protected function get_rest_namespaces() { | |
| 28 | - return apply_filters( | |
| 29 | - 'lp_rest_api_get_rest_namespaces', | |
| 30 | - array( | |
| 31 | - 'learnpress/v1' => $this->get_v1_controllers(), | |
| 32 | - ) | |
| 33 | - ); | |
| 34 | - } | |
| 35 | - | |
| 36 | - protected function get_v1_controllers() { | |
| 37 | - return array( | |
| 38 | - 'courses' => 'LP_Jwt_Courses_V1_Controller', | |
| 39 | - 'lessons' => 'LP_Jwt_Lessons_V1_Controller', | |
| 40 | - 'quiz' => 'LP_Jwt_Quiz_V1_Controller', | |
| 41 | - 'questions' => 'LP_Jwt_Questions_V1_Controller', | |
| 42 | - 'users' => 'LP_Jwt_Users_V1_Controller', | |
| 43 | - 'course_category' => 'LP_Jwt_Course_Category_V1_Controller', | |
| 44 | - 'sections' => 'LP_Jwt_Sections_V1_Controller', | |
| 45 | - 'section-items' => 'LP_Jwt_Section_Items_V1_Controller', | |
| 46 | - ); | |
| 47 | - } | |
| 48 | - | |
| 49 | - public static function get_path() { | |
| 50 | - return dirname( __DIR__ ); | |
| 51 | - } | |
| 52 | - | |
| 53 | - final public static function instance() { | |
| 54 | - if ( null === static::$instance ) { | |
| 55 | - static::$instance = new static(); | |
| 56 | - } | |
| 57 | - return static::$instance; | |
| 58 | - } | |
| 59 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Initialize this version of the REST API. | |
| 4 | + * | |
| 5 | + * @author Nhamdv <daonham95@gmail.com> | |
| 6 | + * @package LP/JWT/RestApi | |
| 7 | + */ | |
| 8 | +class LP_Jwt_RestApi { | |
| 9 | + | |
| 10 | + protected static $instance = null; | |
| 11 | + | |
| 12 | + protected $controllers = array(); | |
| 13 | + | |
| 14 | + public function init() { | |
| 15 | + add_action( 'rest_api_init', array( $this, 'register_rest_routes' ), 10 ); | |
| 16 | + } | |
| 17 | + | |
| 18 | + public function register_rest_routes() { | |
| 19 | + foreach ( $this->get_rest_namespaces() as $namespace => $controllers ) { | |
| 20 | + foreach ( $controllers as $controller_name => $controller_class ) { | |
| 21 | + $this->controllers[ $namespace ][ $controller_name ] = new $controller_class(); | |
| 22 | + $this->controllers[ $namespace ][ $controller_name ]->register_routes(); | |
| 23 | + } | |
| 24 | + } | |
| 25 | + } | |
| 26 | + | |
| 27 | + protected function get_rest_namespaces() { | |
| 28 | + return apply_filters( | |
| 29 | + 'lp_rest_api_get_rest_namespaces', | |
| 30 | + array( | |
| 31 | + 'learnpress/v1' => $this->get_v1_controllers(), | |
| 32 | + ) | |
| 33 | + ); | |
| 34 | + } | |
| 35 | + | |
| 36 | + protected function get_v1_controllers() { | |
| 37 | + return array( | |
| 38 | + 'courses' => 'LP_Jwt_Courses_V1_Controller', | |
| 39 | + 'lessons' => 'LP_Jwt_Lessons_V1_Controller', | |
| 40 | + 'quiz' => 'LP_Jwt_Quiz_V1_Controller', | |
| 41 | + 'questions' => 'LP_Jwt_Questions_V1_Controller', | |
| 42 | + 'users' => 'LP_Jwt_Users_V1_Controller', | |
| 43 | + 'course_category' => 'LP_Jwt_Course_Category_V1_Controller', | |
| 44 | + 'sections' => 'LP_Jwt_Sections_V1_Controller', | |
| 45 | + 'section-items' => 'LP_Jwt_Section_Items_V1_Controller', | |
| 46 | + ); | |
| 47 | + } | |
| 48 | + | |
| 49 | + public static function get_path() { | |
| 50 | + return dirname( __DIR__ ); | |
| 51 | + } | |
| 52 | + | |
| 53 | + final public static function instance() { | |
| 54 | + if ( null === static::$instance ) { | |
| 55 | + static::$instance = new static(); | |
| 56 | + } | |
| 57 | + return static::$instance; | |
| 58 | + } | |
| 59 | +} | |