-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextrachill-api.php
More file actions
118 lines (98 loc) · 3.02 KB
/
extrachill-api.php
File metadata and controls
118 lines (98 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* Plugin Name: Extra Chill API
* Plugin URI: https://extrachill.com
* Description: Central REST API infrastructure for the Extra Chill multisite network.
* Version: 0.14.6
* Author: Extra Chill
* Author URI: https://extrachill.com
* Network: true
* Text Domain: extrachill-api
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Load Composer autoloader for dependencies (Endroid QR Code)
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require_once __DIR__ . '/vendor/autoload.php';
}
if ( ! defined( 'EXTRACHILL_API_PATH' ) ) {
define( 'EXTRACHILL_API_PATH', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'EXTRACHILL_API_URL' ) ) {
define( 'EXTRACHILL_API_URL', plugin_dir_url( __FILE__ ) );
}
final class ExtraChill_API_Plugin {
/**
* Singleton instance storage.
*
* @var ExtraChill_API_Plugin|null
*/
private static $instance = null;
/**
* Bootstraps plugin hooks.
*/
private function __construct() {
$this->load_route_files();
$this->load_middleware();
add_action( 'plugins_loaded', array( $this, 'boot' ) );
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
}
/**
* Returns shared instance.
*
* @return ExtraChill_API_Plugin
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Placeholder bootstrap for future setup.
*/
public function boot() {
require_once EXTRACHILL_API_PATH . 'inc/auth/extrachill-link-auth.php';
require_once EXTRACHILL_API_PATH . 'inc/utils/id-generator.php';
require_once EXTRACHILL_API_PATH . 'inc/utils/bbpress-drafts.php';
do_action( 'extrachill_api_bootstrap' );
}
/**
* Loads all route files so each endpoint can self-register.
*/
private function load_route_files() {
$routes_dir = EXTRACHILL_API_PATH . 'inc/routes/';
if ( ! is_dir( $routes_dir ) ) {
return;
}
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator( $routes_dir, RecursiveDirectoryIterator::SKIP_DOTS )
);
foreach ( $iterator as $file ) {
if ( 'php' !== $file->getExtension() ) {
continue;
}
require_once $file->getRealPath();
}
}
/**
* Loads middleware files for request interception.
*/
private function load_middleware() {
$middleware_dir = EXTRACHILL_API_PATH . 'inc/middleware/';
if ( ! is_dir( $middleware_dir ) ) {
return;
}
foreach ( glob( $middleware_dir . '*.php' ) as $file ) {
require_once $file;
}
}
/**
* Registers REST routes. Will be populated as endpoints migrate into this plugin.
*/
public function register_routes() {
do_action( 'extrachill_api_register_routes' );
}
}
ExtraChill_API_Plugin::get_instance();