| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Routes\Integrations; |
| 4 |
|
| 5 |
// phpcs:disable PSR1.Files.SideEffects |
| 6 |
if (!defined('ABSPATH')) { |
| 7 |
exit; // Exit if accessed directly |
| 8 |
} |
| 9 |
|
| 10 |
use IvyForms\Vendor\DI\Container; |
| 11 |
use IvyForms\Vendor\DI\DependencyException; |
| 12 |
use IvyForms\Vendor\DI\NotFoundException; |
| 13 |
use IvyForms\Controllers\Integrations\InstallPluginController; |
| 14 |
use IvyForms\Controllers\Integration\GetAllIntegrationsController; |
| 15 |
use IvyForms\Controllers\Integration\GetIntegrationController; |
| 16 |
|
| 17 |
/** |
| 18 |
* Class Integrations |
| 19 |
* |
| 20 |
* Registers REST API routes for integrations |
| 21 |
* |
| 22 |
* @package IvyForms\Routes\Integrations |
| 23 |
*/ |
| 24 |
class Integrations |
| 25 |
{ |
| 26 |
/** |
| 27 |
* Register integrations routes |
| 28 |
* |
| 29 |
* @param Container $container |
| 30 |
* @param string $routeNamespace |
| 31 |
* |
| 32 |
* @throws DependencyException |
| 33 |
* @throws NotFoundException |
| 34 |
*/ |
| 35 |
public static function registerRoutes(Container $container, string $routeNamespace): void |
| 36 |
{ |
| 37 |
// Get all integrations |
| 38 |
register_rest_route( |
| 39 |
$routeNamespace, |
| 40 |
'/integrations', |
| 41 |
[ |
| 42 |
'methods' => 'GET', |
| 43 |
'callback' => $container->get(GetAllIntegrationsController::class), |
| 44 |
'permission_callback' => function () { |
| 45 |
return current_user_can('manage_options'); |
| 46 |
}, |
| 47 |
] |
| 48 |
); |
| 49 |
|
| 50 |
// Get single integration |
| 51 |
register_rest_route( |
| 52 |
$routeNamespace, |
| 53 |
'/integrations/(?P<slug>[a-zA-Z0-9_-]+)', |
| 54 |
[ |
| 55 |
'methods' => 'GET', |
| 56 |
'callback' => $container->get(GetIntegrationController::class), |
| 57 |
'permission_callback' => function () { |
| 58 |
return current_user_can('manage_options'); |
| 59 |
}, |
| 60 |
] |
| 61 |
); |
| 62 |
|
| 63 |
// Install plugin endpoint |
| 64 |
register_rest_route( |
| 65 |
$routeNamespace, |
| 66 |
'/integrations/install-plugin', |
| 67 |
[ |
| 68 |
'methods' => 'POST', |
| 69 |
'callback' => [$container->get(InstallPluginController::class), 'install'], |
| 70 |
'permission_callback' => function () { |
| 71 |
return current_user_can('install_plugins') && current_user_can('activate_plugins'); |
| 72 |
}, |
| 73 |
] |
| 74 |
); |
| 75 |
} |
| 76 |
} |
| 77 |
|