| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Routes\Confirmation; |
| 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\Confirmation\AddConfirmationController; |
| 14 |
use IvyForms\Controllers\Confirmation\GetConfirmationsController; |
| 15 |
use IvyForms\Controllers\Confirmation\GetConformationController; |
| 16 |
use IvyForms\Controllers\Confirmation\UpdateConfirmationController; |
| 17 |
use WP_REST_Server; |
| 18 |
|
| 19 |
class Confirmation |
| 20 |
{ |
| 21 |
/** |
| 22 |
* @throws DependencyException |
| 23 |
* @throws NotFoundException |
| 24 |
*/ |
| 25 |
public static function registerRoutes(Container $container, string $routeNamespace): void |
| 26 |
{ |
| 27 |
register_rest_route( |
| 28 |
$routeNamespace, |
| 29 |
'/confirmation/(?P<id>\d+)', |
| 30 |
[ |
| 31 |
'methods' => WP_REST_Server::READABLE, |
| 32 |
'callback' => $container->get(GetConformationController::class), |
| 33 |
'permission_callback' => function () { |
| 34 |
return current_user_can('manage_options'); |
| 35 |
}, |
| 36 |
] |
| 37 |
); |
| 38 |
|
| 39 |
register_rest_route( |
| 40 |
$routeNamespace, |
| 41 |
'/confirmations/(?P<id>\d+)', |
| 42 |
[ |
| 43 |
'methods' => WP_REST_Server::READABLE, |
| 44 |
'callback' => $container->get(GetConfirmationsController::class), |
| 45 |
'permission_callback' => function () { |
| 46 |
return current_user_can('manage_options'); |
| 47 |
}, |
| 48 |
] |
| 49 |
); |
| 50 |
|
| 51 |
register_rest_route( |
| 52 |
$routeNamespace, |
| 53 |
'/confirmation/add/', |
| 54 |
[ |
| 55 |
'methods' => WP_REST_Server::CREATABLE, |
| 56 |
'callback' => $container->get(AddConfirmationController::class), |
| 57 |
'permission_callback' => function () { |
| 58 |
return current_user_can('manage_options'); |
| 59 |
} |
| 60 |
] |
| 61 |
); |
| 62 |
|
| 63 |
register_rest_route( |
| 64 |
$routeNamespace, |
| 65 |
'/confirmation/update/(?P<id>\d+)', |
| 66 |
[ |
| 67 |
'methods' => WP_REST_Server::CREATABLE, |
| 68 |
'callback' => $container->get(UpdateConfirmationController::class), |
| 69 |
'permission_callback' => function () { |
| 70 |
return current_user_can('manage_options'); |
| 71 |
} |
| 72 |
] |
| 73 |
); |
| 74 |
} |
| 75 |
} |
| 76 |
|