| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Routes\Entry; |
| 4 |
|
| 5 |
// phpcs:disable PSR1.Files.SideEffects |
| 6 |
if (!defined('ABSPATH')) { |
| 7 |
exit; // Exit if accessed directly |
| 8 |
} |
| 9 |
|
| 10 |
use DI\Container; |
| 11 |
use DI\DependencyException; |
| 12 |
use DI\NotFoundException; |
| 13 |
use IvyForms\Controllers\Entry\AddEntryController; |
| 14 |
use IvyForms\Controllers\Entry\DeleteEntriesController; |
| 15 |
use IvyForms\Controllers\Entry\DeleteEntryController; |
| 16 |
use IvyForms\Controllers\Entry\GetEntryController; |
| 17 |
use IvyForms\Controllers\Entry\GetEntryCountController; |
| 18 |
use IvyForms\Controllers\Entry\SearchEntriesController; |
| 19 |
use IvyForms\Controllers\Entry\UpdateEntryStarredController; |
| 20 |
use IvyForms\Controllers\Entry\UpdateEntryStatusController; |
| 21 |
use WP_REST_Server; |
| 22 |
|
| 23 |
class Entry |
| 24 |
{ |
| 25 |
/** |
| 26 |
* @throws DependencyException |
| 27 |
* @throws NotFoundException |
| 28 |
*/ |
| 29 |
public static function registerRoutes(Container $container, string $routeNamespace): void |
| 30 |
{ |
| 31 |
// TODO - Add IvyForms capability - Admin only for now |
| 32 |
register_rest_route( |
| 33 |
$routeNamespace, |
| 34 |
'/entry/(?P<id>\d+)', |
| 35 |
[ |
| 36 |
'methods' => WP_REST_Server::READABLE, |
| 37 |
'callback' => $container->get(GetEntryController::class), |
| 38 |
'permission_callback' => function () { |
| 39 |
return current_user_can('manage_options'); |
| 40 |
} |
| 41 |
] |
| 42 |
); |
| 43 |
|
| 44 |
register_rest_route( |
| 45 |
$routeNamespace, |
| 46 |
'/entry/add/', |
| 47 |
[ |
| 48 |
'methods' => WP_REST_Server::CREATABLE, |
| 49 |
'callback' => $container->get(AddEntryController::class), |
| 50 |
'permission_callback' => function () { |
| 51 |
return current_user_can('manage_options'); |
| 52 |
} |
| 53 |
] |
| 54 |
); |
| 55 |
|
| 56 |
register_rest_route( |
| 57 |
$routeNamespace, |
| 58 |
'/entries/search', |
| 59 |
[ |
| 60 |
'methods' => WP_REST_Server::READABLE, |
| 61 |
'callback' => $container->get(SearchEntriesController::class), |
| 62 |
'permission_callback' => function () { |
| 63 |
return current_user_can('manage_options'); |
| 64 |
} |
| 65 |
] |
| 66 |
); |
| 67 |
|
| 68 |
register_rest_route( |
| 69 |
$routeNamespace, |
| 70 |
'/entries/delete', |
| 71 |
[ |
| 72 |
'methods' => WP_REST_Server::CREATABLE, |
| 73 |
'callback' => $container->get(DeleteEntriesController::class), |
| 74 |
'permission_callback' => function () { |
| 75 |
return current_user_can('manage_options'); |
| 76 |
} |
| 77 |
] |
| 78 |
); |
| 79 |
register_rest_route( |
| 80 |
$routeNamespace, |
| 81 |
'/entry/delete/(?P<id>\d+)', |
| 82 |
[ |
| 83 |
'methods' => WP_REST_Server::CREATABLE, |
| 84 |
'callback' => $container->get(DeleteEntryController::class), |
| 85 |
'permission_callback' => function () { |
| 86 |
return current_user_can('manage_options'); |
| 87 |
} |
| 88 |
] |
| 89 |
); |
| 90 |
|
| 91 |
register_rest_route( |
| 92 |
$routeNamespace, |
| 93 |
'/entry/update/starred/(?P<id>\d+)', |
| 94 |
[ |
| 95 |
'methods' => WP_REST_Server::CREATABLE, |
| 96 |
'callback' => $container->get(UpdateEntryStarredController::class), |
| 97 |
'permission_callback' => function () { |
| 98 |
return current_user_can('manage_options'); |
| 99 |
} |
| 100 |
] |
| 101 |
); |
| 102 |
|
| 103 |
register_rest_route( |
| 104 |
$routeNamespace, |
| 105 |
'/entry/update/status/(?P<id>\d+)', |
| 106 |
[ |
| 107 |
'methods' => WP_REST_Server::CREATABLE, |
| 108 |
'callback' => $container->get(UpdateEntryStatusController::class), |
| 109 |
'permission_callback' => function () { |
| 110 |
return current_user_can('manage_options'); |
| 111 |
} |
| 112 |
] |
| 113 |
); |
| 114 |
|
| 115 |
register_rest_route( |
| 116 |
$routeNamespace, |
| 117 |
'/entries/count', |
| 118 |
[ |
| 119 |
'methods' => WP_REST_Server::READABLE, |
| 120 |
'callback' => $container->get(GetEntryCountController::class), |
| 121 |
'permission_callback' => function () { |
| 122 |
return current_user_can('manage_options'); |
| 123 |
} |
| 124 |
] |
| 125 |
); |
| 126 |
} |
| 127 |
} |
| 128 |
|