Newer
Older
<?php
/**
* Base controller class.
*
*/
namespace CiviCRM_WP_REST\Controller;
use CiviCRM_WP_REST\Endpoint\Endpoint_Interface;
abstract class Base extends \WP_REST_Controller implements Endpoint_Interface {
* @return string $namespace
*/
public function get_namespace() {
* @return string $rest_base
*/
public function get_rest_base() {
/**
* Retrieves the endpoint ie. '/civicrm/v3/rest'.
*
* @return string $rest_base
*/
public function get_endpoint() {
return '/' . $this->get_namespace() . $this->get_rest_base();
/**
* Checks whether the requested route is equal to this endpoint.
*
* @param WP_REST_Request $request
* @return bool $is_current_endpoint True if it's equal, false otherwise
*/
public function is_current_endpoint($request) {
* @return int $status
*/
protected function authorization_status_code() {
* @param string|\CRM_Core_Exception|\WP_Error $error
* @param mixed $data Error data
* @return WP_Error $error
*/
protected function civi_rest_error($error, $data = []) {
return new \WP_Error('civicrm_rest_api_error', $error, empty($data) ? ['status' => $this->authorization_status_code()] : $data);
}