| @@ -1,92 +1,92 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * Class LP_API_Base | |
| 5 | - * | |
| 6 | - * Base class for api | |
| 7 | - * | |
| 8 | - * @since 3.2.6 | |
| 9 | - */ | |
| 10 | -abstract class LP_Abstract_API { | |
| 11 | - /** | |
| 12 | - * @var string | |
| 13 | - */ | |
| 14 | - public $version = 'v1'; | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * @var string | |
| 18 | - */ | |
| 19 | - public $endpoint = ''; | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * @var WC_REST_Controller[]|string[] | |
| 23 | - */ | |
| 24 | - public $controllers = array(); | |
| 25 | - | |
| 26 | - /** | |
| 27 | - * LP_API_Base constructor. | |
| 28 | - */ | |
| 29 | - public function __construct() { | |
| 30 | - $this->rest_api_init(); | |
| 31 | - } | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * Init REST. | |
| 35 | - * | |
| 36 | - * @since 3.2.6 | |
| 37 | - */ | |
| 38 | - public function rest_api_init() { | |
| 39 | - if ( ! class_exists( 'WP_REST_Server' ) ) { | |
| 40 | - return; | |
| 41 | - } | |
| 42 | - | |
| 43 | - if ( ! LP_Helper::isRestApiLP() ) { | |
| 44 | - return; | |
| 45 | - } | |
| 46 | - | |
| 47 | - $this->rest_api_includes(); | |
| 48 | - | |
| 49 | - add_action( 'rest_api_init', array( $this, 'rest_api_register_routes' ), 10 ); | |
| 50 | - | |
| 51 | - } | |
| 52 | - | |
| 53 | - public function rest_api_includes() { | |
| 54 | - | |
| 55 | - } | |
| 56 | - | |
| 57 | - /** | |
| 58 | - * Register routes | |
| 59 | - * | |
| 60 | - * @since 3.2.6 | |
| 61 | - */ | |
| 62 | - public function rest_api_register_routes() { | |
| 63 | - if ( ! $this->controllers ) { | |
| 64 | - return; | |
| 65 | - } | |
| 66 | - | |
| 67 | - $controllers = array(); | |
| 68 | - | |
| 69 | - foreach ( $this->controllers as $name => $controller ) { | |
| 70 | - | |
| 71 | - if ( is_string( $controller ) ) { | |
| 72 | - $name = $controller; | |
| 73 | - $controllers[ $name ] = new $controller(); | |
| 74 | - } else { | |
| 75 | - $controllers[ $name ] = $controller; | |
| 76 | - } | |
| 77 | - | |
| 78 | - $controllers[ $name ]->register_routes(); | |
| 79 | - } | |
| 80 | - | |
| 81 | - $this->controllers = $controllers; | |
| 82 | - } | |
| 83 | - | |
| 84 | - /** | |
| 85 | - * Check permission if user is administrator. | |
| 86 | - * | |
| 87 | - * @return bool | |
| 88 | - */ | |
| 89 | - public static function check_admin_permission(): bool { | |
| 90 | - return current_user_can( ADMIN_ROLE ); | |
| 91 | - } | |
| 92 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Class LP_API_Base | |
| 5 | + * | |
| 6 | + * Base class for api | |
| 7 | + * | |
| 8 | + * @since 3.2.6 | |
| 9 | + */ | |
| 10 | +abstract class LP_Abstract_API { | |
| 11 | + /** | |
| 12 | + * @var string | |
| 13 | + */ | |
| 14 | + public $version = 'v1'; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * @var string | |
| 18 | + */ | |
| 19 | + public $endpoint = ''; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * @var WC_REST_Controller[]|string[] | |
| 23 | + */ | |
| 24 | + public $controllers = array(); | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * LP_API_Base constructor. | |
| 28 | + */ | |
| 29 | + public function __construct() { | |
| 30 | + $this->rest_api_init(); | |
| 31 | + } | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * Init REST. | |
| 35 | + * | |
| 36 | + * @since 3.2.6 | |
| 37 | + */ | |
| 38 | + public function rest_api_init() { | |
| 39 | + if ( ! class_exists( 'WP_REST_Server' ) ) { | |
| 40 | + return; | |
| 41 | + } | |
| 42 | + | |
| 43 | + if ( ! LP_Helper::isRestApiLP() ) { | |
| 44 | + return; | |
| 45 | + } | |
| 46 | + | |
| 47 | + $this->rest_api_includes(); | |
| 48 | + | |
| 49 | + add_action( 'rest_api_init', array( $this, 'rest_api_register_routes' ), 10 ); | |
| 50 | + | |
| 51 | + } | |
| 52 | + | |
| 53 | + public function rest_api_includes() { | |
| 54 | + | |
| 55 | + } | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * Register routes | |
| 59 | + * | |
| 60 | + * @since 3.2.6 | |
| 61 | + */ | |
| 62 | + public function rest_api_register_routes() { | |
| 63 | + if ( ! $this->controllers ) { | |
| 64 | + return; | |
| 65 | + } | |
| 66 | + | |
| 67 | + $controllers = array(); | |
| 68 | + | |
| 69 | + foreach ( $this->controllers as $name => $controller ) { | |
| 70 | + | |
| 71 | + if ( is_string( $controller ) ) { | |
| 72 | + $name = $controller; | |
| 73 | + $controllers[ $name ] = new $controller(); | |
| 74 | + } else { | |
| 75 | + $controllers[ $name ] = $controller; | |
| 76 | + } | |
| 77 | + | |
| 78 | + $controllers[ $name ]->register_routes(); | |
| 79 | + } | |
| 80 | + | |
| 81 | + $this->controllers = $controllers; | |
| 82 | + } | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * Check permission if user is administrator. | |
| 86 | + * | |
| 87 | + * @return bool | |
| 88 | + */ | |
| 89 | + public static function check_admin_permission(): bool { | |
| 90 | + return current_user_can( ADMIN_ROLE ); | |
| 91 | + } | |
| 92 | +} | |