| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Loads the Qcformbuilder Forms REST API |
| 5 |
* |
| 6 |
* @package Caldera_Forms Modified by QuantumCloud |
| 7 |
* @author Josh Pollock <Josh@CalderaWP.com> |
| 8 |
* @license GPL-2.0+ |
| 9 |
* @link |
| 10 |
* @copyright 2016 CalderaWP LLC |
| 11 |
*/ |
| 12 |
class Qcformbuilder_Forms_API_Load { |
| 13 |
|
| 14 |
/** |
| 15 |
* Array of route objects for this collection |
| 16 |
* |
| 17 |
* @since 1.4.4 |
| 18 |
* |
| 19 |
* @var array |
| 20 |
*/ |
| 21 |
protected $routes; |
| 22 |
|
| 23 |
/** |
| 24 |
* Namespace for this route collection |
| 25 |
* |
| 26 |
* @since 1.4.4 |
| 27 |
* |
| 28 |
* @var string |
| 29 |
*/ |
| 30 |
protected $namespace; |
| 31 |
|
| 32 |
/** |
| 33 |
* Qcformbuilder_Forms_API_Load constructor. |
| 34 |
* |
| 35 |
* @since 1.4.4 |
| 36 |
* |
| 37 |
* @param string $namespace Namespace for this route collection |
| 38 |
*/ |
| 39 |
public function __construct( $namespace ) { |
| 40 |
$this->namespace = $namespace; |
| 41 |
$this->routes = array(); |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Add a route to this collection |
| 47 |
* |
| 48 |
* @since 1.4.4 |
| 49 |
* |
| 50 |
* @param Qcformbuilder_Forms_API_Route $route |
| 51 |
*/ |
| 52 |
public function add_route( Qcformbuilder_Forms_API_Route $route ){ |
| 53 |
$this->routes[] = $route; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Initialize routes for this namespace |
| 58 |
* |
| 59 |
* @since 1.4.4 |
| 60 |
* |
| 61 |
* @return bool True if loading happened, false if not |
| 62 |
*/ |
| 63 |
public function init_routes(){ |
| 64 |
if( ! empty( $this->routes ) && ! did_action( "qcformbuilder_forms_rest_api_init_$this->namespace" ) ){ |
| 65 |
/** @var Qcformbuilder_Forms_API_Route $route */ |
| 66 |
foreach ( $this->routes as $route ){ |
| 67 |
$route->add_routes( $this->namespace ); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Runs after Qcformbuilder Forms REST API is loaded |
| 72 |
* |
| 73 |
* Dynamic part of hook is the namespace, so may run for each version |
| 74 |
* |
| 75 |
* @since 1.4.4 |
| 76 |
* |
| 77 |
* @param array $routes Route objects that were added. |
| 78 |
*/ |
| 79 |
do_action( "qcformbuilder_forms_rest_api_init_$this->namespace", $this->routes ); |
| 80 |
|
| 81 |
return true; |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
return false; |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
} |