| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Routes\Notification; |
| 4 |
|
| 5 |
use IvyForms\Vendor\DI\Container; |
| 6 |
use IvyForms\Vendor\DI\DependencyException; |
| 7 |
use IvyForms\Vendor\DI\NotFoundException; |
| 8 |
use IvyForms\Controllers\Notification\AddNotificationController; |
| 9 |
use IvyForms\Controllers\Notification\DeleteNotificationController; |
| 10 |
use IvyForms\Controllers\Notification\DuplicateNotificationController; |
| 11 |
use IvyForms\Controllers\Notification\GetNotificationController; |
| 12 |
use IvyForms\Controllers\Notification\GetNotificationsController; |
| 13 |
use IvyForms\Controllers\Notification\SearchNotificationsController; |
| 14 |
use IvyForms\Controllers\Notification\UpdateNotificationController; |
| 15 |
use WP_REST_Server; |
| 16 |
|
| 17 |
class Notification |
| 18 |
{ |
| 19 |
/** |
| 20 |
* @throws DependencyException |
| 21 |
* @throws NotFoundException |
| 22 |
*/ |
| 23 |
public static function registerRoutes(Container $container, string $routeNamespace): void |
| 24 |
{ |
| 25 |
register_rest_route( |
| 26 |
$routeNamespace, |
| 27 |
'/notification/(?P<id>\d+)', |
| 28 |
[ |
| 29 |
'methods' => WP_REST_Server::READABLE, |
| 30 |
'callback' => $container->get(GetNotificationController::class), |
| 31 |
'permission_callback' => function () { |
| 32 |
return current_user_can('manage_options'); |
| 33 |
}, |
| 34 |
] |
| 35 |
); |
| 36 |
|
| 37 |
register_rest_route( |
| 38 |
$routeNamespace, |
| 39 |
'/notifications/(?P<id>\d+)', |
| 40 |
[ |
| 41 |
'methods' => WP_REST_Server::READABLE, |
| 42 |
'callback' => $container->get(GetNotificationsController::class), |
| 43 |
'permission_callback' => function () { |
| 44 |
return current_user_can('manage_options'); |
| 45 |
} |
| 46 |
] |
| 47 |
); |
| 48 |
|
| 49 |
register_rest_route( |
| 50 |
$routeNamespace, |
| 51 |
'/notification/add/', |
| 52 |
[ |
| 53 |
'methods' => WP_REST_Server::CREATABLE, |
| 54 |
'callback' => $container->get(AddNotificationController::class), |
| 55 |
'permission_callback' => function () { |
| 56 |
return current_user_can('manage_options'); |
| 57 |
} |
| 58 |
] |
| 59 |
); |
| 60 |
|
| 61 |
register_rest_route( |
| 62 |
$routeNamespace, |
| 63 |
'/notification/update/(?P<id>\d+)', |
| 64 |
[ |
| 65 |
'methods' => WP_REST_Server::CREATABLE, |
| 66 |
'callback' => $container->get(UpdateNotificationController::class), |
| 67 |
'permission_callback' => function () { |
| 68 |
return current_user_can('manage_options'); |
| 69 |
} |
| 70 |
] |
| 71 |
); |
| 72 |
|
| 73 |
register_rest_route( |
| 74 |
$routeNamespace, |
| 75 |
'/notification/delete/(?P<id>\d+)', |
| 76 |
[ |
| 77 |
'methods' => WP_REST_Server::CREATABLE, |
| 78 |
'callback' => $container->get(DeleteNotificationController::class), |
| 79 |
'permission_callback' => function () { |
| 80 |
return current_user_can('manage_options'); |
| 81 |
} |
| 82 |
] |
| 83 |
); |
| 84 |
register_rest_route( |
| 85 |
$routeNamespace, |
| 86 |
'/notification/duplicate/(?P<id>\d+)', |
| 87 |
[ |
| 88 |
'methods' => WP_REST_Server::CREATABLE, |
| 89 |
'callback' => $container->get(DuplicateNotificationController::class), |
| 90 |
// TODO - Add IvyForms capability - Admin only for now |
| 91 |
'permission_callback' => function () { |
| 92 |
return current_user_can('manage_options'); |
| 93 |
} |
| 94 |
] |
| 95 |
); |
| 96 |
|
| 97 |
register_rest_route( |
| 98 |
$routeNamespace, |
| 99 |
'/notifications/search', |
| 100 |
[ |
| 101 |
'methods' => WP_REST_Server::READABLE, |
| 102 |
'callback' => $container->get(SearchNotificationsController::class), |
| 103 |
'permission_callback' => function () { |
| 104 |
return current_user_can('manage_options'); |
| 105 |
} |
| 106 |
] |
| 107 |
); |
| 108 |
} |
| 109 |
} |
| 110 |
|