| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yatra\Core\API; |
| 4 |
|
| 5 |
abstract class RestBase |
| 6 |
{ |
| 7 |
protected $rest_route_id = ''; |
| 8 |
|
| 9 |
protected $namespace = YATRA_REST_WEBHOOKS_NAMESPACE; |
| 10 |
|
| 11 |
|
| 12 |
protected $method = \WP_REST_Server::READABLE; |
| 13 |
|
| 14 |
|
| 15 |
public function __construct() |
| 16 |
{ |
| 17 |
add_action('rest_api_init', array($this, 'register_routes')); |
| 18 |
} |
| 19 |
|
| 20 |
public function register_routes() |
| 21 |
{ |
| 22 |
register_rest_route($this->namespace, $this->rest_route_id, array( |
| 23 |
'methods' => $this->method, |
| 24 |
'permission_callback' => array($this, 'validate'), |
| 25 |
'callback' => array($this, 'handle') |
| 26 |
)); |
| 27 |
} |
| 28 |
|
| 29 |
abstract public function validate(\WP_REST_Request $request); |
| 30 |
|
| 31 |
abstract public function handle(\WP_REST_Request $request); |
| 32 |
|
| 33 |
abstract public static function init(); |
| 34 |
|
| 35 |
} |
| 36 |
|
| 37 |
|