| 1 |
<?php |
| 2 |
|
| 3 |
namespace Code_Snippets\REST_API\Cloud; |
| 4 |
|
| 5 |
use Code_Snippets\Client\Cloud_API; |
| 6 |
use Code_Snippets\REST_API\REST_Collection_Controller; |
| 7 |
use Code_Snippets\REST_API\REST_Controller; |
| 8 |
use WP_REST_Request; |
| 9 |
|
| 10 |
/** |
| 11 |
* Base class for REST API controllers that interface with the Code Snippets Cloud API. |
| 12 |
* |
| 13 |
* @package Code_Snippets |
| 14 |
*/ |
| 15 |
abstract class Cloud_Collection_REST_Controller extends REST_Collection_Controller { |
| 16 |
|
| 17 |
/** |
| 18 |
* Instance of Cloud API class. |
| 19 |
* |
| 20 |
* @var Cloud_API |
| 21 |
*/ |
| 22 |
protected Cloud_API $cloud_api; |
| 23 |
|
| 24 |
/** |
| 25 |
* Class constructor. |
| 26 |
* |
| 27 |
* @param Cloud_API $cloud_api Cloud API instance. |
| 28 |
*/ |
| 29 |
public function __construct( Cloud_API $cloud_api ) { |
| 30 |
parent::__construct(); |
| 31 |
$this->cloud_api = $cloud_api; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Check the request from Cloud API is valid |
| 36 |
* |
| 37 |
* @param WP_REST_Request $request Full data about the request. |
| 38 |
* |
| 39 |
* @return bool |
| 40 |
*/ |
| 41 |
public function create_item_permissions_check( $request ): bool { |
| 42 |
return parent::create_item_permissions_check( $request ) && |
| 43 |
$request->get_header( 'Access-Control' ) === $this->cloud_api->get_local_token(); |
| 44 |
} |
| 45 |
} |
| 46 |
|