2019-09-10 06:27:33 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2019-09-28 11:39:55 +02:00
|
|
|
* Define
|
|
|
|
* Note: only use for internal purpose.
|
2019-09-10 06:27:33 +02:00
|
|
|
*
|
2019-09-28 11:39:55 +02:00
|
|
|
* @package OpalJob
|
|
|
|
* @copyright Copyright (c) 2019, WpOpal <https://www.wpopal.com>
|
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License
|
|
|
|
* @since 1.0
|
2019-09-10 06:27:33 +02:00
|
|
|
*/
|
2019-09-28 11:39:55 +02:00
|
|
|
// namespace Opal_Job\API;
|
|
|
|
// Exit if accessed directly.
|
2019-09-10 06:27:33 +02:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
2019-09-28 11:39:55 +02:00
|
|
|
use Opal_Job\API\Api_Auth;
|
|
|
|
use Opal_Job\API\API_Admin;
|
2019-09-10 06:27:33 +02:00
|
|
|
|
|
|
|
/**
|
2019-09-28 11:39:55 +02:00
|
|
|
* Abstract class to define/implement base methods for all controller classes
|
2019-09-10 06:27:33 +02:00
|
|
|
*
|
2019-09-28 11:39:55 +02:00
|
|
|
* @since 1.0.0
|
|
|
|
* @package Opal_Job
|
|
|
|
* @subpackage Opal_Job/controllers
|
2019-09-10 06:27:33 +02:00
|
|
|
*/
|
|
|
|
class Opalestate_API {
|
2019-09-28 11:39:55 +02:00
|
|
|
|
2019-09-10 06:27:33 +02:00
|
|
|
/**
|
2019-09-28 11:39:55 +02:00
|
|
|
* The unique identifier of this plugin.
|
2019-09-10 06:27:33 +02:00
|
|
|
*
|
2019-09-28 11:39:55 +02:00
|
|
|
* @since 1.0.0
|
|
|
|
* @access protected
|
|
|
|
* @var string $plugin_base_name The string used to uniquely identify this plugin.
|
|
|
|
*/
|
|
|
|
public $base = 'job-api';
|
2019-09-10 06:27:33 +02:00
|
|
|
|
2019-09-28 11:39:55 +02:00
|
|
|
public function __construct () {
|
|
|
|
return $this->init();
|
2019-09-10 06:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a new rewrite endpoint for accessing the API
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*
|
|
|
|
* @param array $rewrite_rules WordPress Rewrite Rules
|
|
|
|
*
|
|
|
|
* @since 1.1
|
|
|
|
*/
|
2019-09-28 11:39:55 +02:00
|
|
|
public function init() {
|
|
|
|
|
|
|
|
$this->includes( [
|
|
|
|
'class-base-api.php',
|
|
|
|
'v1/property.php',
|
|
|
|
'v1/agent.php',
|
|
|
|
'v1/agency.php',
|
|
|
|
'class-api-auth.php'
|
|
|
|
] );
|
2019-09-10 06:27:33 +02:00
|
|
|
|
2019-09-28 11:39:55 +02:00
|
|
|
add_action( 'rest_api_init', [$this,'register_resources'] );
|
2019-09-10 06:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-09-28 11:39:55 +02:00
|
|
|
* Registers a new rewrite endpoint for accessing the API
|
2019-09-10 06:27:33 +02:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*
|
2019-09-28 11:39:55 +02:00
|
|
|
* @param array $rewrite_rules WordPress Rewrite Rules
|
2019-09-10 06:27:33 +02:00
|
|
|
*
|
|
|
|
* @since 1.1
|
|
|
|
*/
|
2019-09-28 11:39:55 +02:00
|
|
|
public function add_endpoint( $rewrite_rules ) {
|
|
|
|
add_rewrite_endpoint( $this->base, EP_ALL );
|
2019-09-10 06:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-09-28 11:39:55 +02:00
|
|
|
* Include list of collection files
|
2019-09-10 06:27:33 +02:00
|
|
|
*
|
2019-09-28 11:39:55 +02:00
|
|
|
* @var array $files
|
2019-09-10 06:27:33 +02:00
|
|
|
*/
|
2019-09-28 11:39:55 +02:00
|
|
|
public function includes( $files ) {
|
|
|
|
foreach ( $files as $file ) {
|
|
|
|
$file = OPALESTATE_PLUGIN_DIR . 'inc/api/' . $file;
|
|
|
|
include_once $file;
|
2019-09-10 06:27:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-09-28 11:39:55 +02:00
|
|
|
* Registers a new rewrite endpoint for accessing the API
|
2019-09-10 06:27:33 +02:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*
|
2019-09-28 11:39:55 +02:00
|
|
|
* @param array $rewrite_rules WordPress Rewrite Rules
|
2019-09-10 06:27:33 +02:00
|
|
|
*
|
|
|
|
* @since 1.1
|
|
|
|
*/
|
2019-09-28 11:39:55 +02:00
|
|
|
public function register_resources ( ) {
|
|
|
|
|
|
|
|
$api_classes = apply_filters( 'opaljob_api_classes',
|
|
|
|
array(
|
|
|
|
'Property_Api',
|
|
|
|
'Agent_Api',
|
|
|
|
'Agency_Api'
|
|
|
|
)
|
|
|
|
);
|
2019-09-10 06:27:33 +02:00
|
|
|
|
2019-09-28 11:39:55 +02:00
|
|
|
|
|
|
|
foreach ( $api_classes as $api_class ) {
|
|
|
|
$api_class = new $api_class( );
|
|
|
|
$api_class->register_routes();
|
2019-09-10 06:27:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-28 11:39:55 +02:00
|
|
|
}
|