class-api.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SearchRegex\Api; |
| 4 | |
| 5 | class Api { |
| 6 | const SEARCHREGEX_API_NAMESPACE = 'search-regex/v1'; |
| 7 | |
| 8 | /** |
| 9 | * Instance variable |
| 10 | */ |
| 11 | private static ?Api $instance = null; |
| 12 | |
| 13 | /** |
| 14 | * Array of endpoint routes |
| 15 | * |
| 16 | * @var Route[] |
| 17 | * @phpstan-ignore property.onlyWritten |
| 18 | */ |
| 19 | private array $routes = []; |
| 20 | |
| 21 | /** |
| 22 | * Create API |
| 23 | * |
| 24 | * @return Api |
| 25 | */ |
| 26 | public static function init() { |
| 27 | if ( is_null( self::$instance ) ) { |
| 28 | self::$instance = new Api(); |
| 29 | } |
| 30 | |
| 31 | return self::$instance; |
| 32 | } |
| 33 | |
| 34 | public function __construct() { |
| 35 | global $wpdb; |
| 36 | |
| 37 | $wpdb->hide_errors(); |
| 38 | |
| 39 | $this->routes[] = new Route\Search_Route( self::SEARCHREGEX_API_NAMESPACE ); |
| 40 | $this->routes[] = new Route\Source_Route( self::SEARCHREGEX_API_NAMESPACE ); |
| 41 | $this->routes[] = new Route\Plugin_Route( self::SEARCHREGEX_API_NAMESPACE ); |
| 42 | $this->routes[] = new Route\Settings_Route( self::SEARCHREGEX_API_NAMESPACE ); |
| 43 | $this->routes[] = new Route\Preset_Route( self::SEARCHREGEX_API_NAMESPACE ); |
| 44 | } |
| 45 | } |
| 46 |