| 1 |
<?php |
| 2 |
/** |
| 3 |
* Abstract controller. |
| 4 |
* |
| 5 |
* @package HivePress\Controllers |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace HivePress\Controllers; |
| 9 |
|
| 10 |
use HivePress\Helpers as hp; |
| 11 |
use HivePress\Traits; |
| 12 |
|
| 13 |
// Exit if accessed directly. |
| 14 |
defined( 'ABSPATH' ) || exit; |
| 15 |
|
| 16 |
/** |
| 17 |
* Abstract controller class. |
| 18 |
* |
| 19 |
* @OA\Server(url="/wp-json/hivepress/v1", description="") |
| 20 |
* @OA\Info( |
| 21 |
* title="HivePress REST API", |
| 22 |
* version="1.0", |
| 23 |
* description="This is a reference of all the endpoints available in HivePress REST API. Since it's based on WordPress REST API, you can refer to the [WordPress documentation](https://developer.wordpress.org/rest-api/) for the available authentication methods and more details." |
| 24 |
* ) |
| 25 |
*/ |
| 26 |
abstract class Controller { |
| 27 |
use Traits\Mutator; |
| 28 |
|
| 29 |
/** |
| 30 |
* Controller routes. |
| 31 |
* |
| 32 |
* @var array |
| 33 |
*/ |
| 34 |
protected $routes = []; |
| 35 |
|
| 36 |
/** |
| 37 |
* Class constructor. |
| 38 |
* |
| 39 |
* @param array $args Controller arguments. |
| 40 |
*/ |
| 41 |
public function __construct( $args = [] ) { |
| 42 |
|
| 43 |
// Set properties. |
| 44 |
foreach ( $args as $name => $value ) { |
| 45 |
$this->set_property( $name, $value ); |
| 46 |
} |
| 47 |
|
| 48 |
// Bootstrap properties. |
| 49 |
$this->boot(); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Bootstraps controller properties. |
| 54 |
*/ |
| 55 |
protected function boot() {} |
| 56 |
|
| 57 |
/** |
| 58 |
* Gets controller routes. |
| 59 |
* |
| 60 |
* @return array |
| 61 |
*/ |
| 62 |
final public function get_routes() { |
| 63 |
return $this->routes; |
| 64 |
} |
| 65 |
} |
| 66 |
|