From 3476807b40332cfeec29714869438b61831053df Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Sat, 6 Nov 2021 10:18:46 +0100 Subject: [PATCH] Added the routes helper file --- application/helpers/routes_helper.php | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 application/helpers/routes_helper.php diff --git a/application/helpers/routes_helper.php b/application/helpers/routes_helper.php new file mode 100644 index 00000000..bc2179a2 --- /dev/null +++ b/application/helpers/routes_helper.php @@ -0,0 +1,31 @@ + + * @copyright Copyright (c) 2013 - 2020, Alex Tselegidis + * @license http://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link http://easyappointments.org + * @since v1.3.0 + * ---------------------------------------------------------------------------- */ + +if ( ! function_exists('route_api_resource')) +{ + /** + * Define a route for an API resource (includes index, store, update and delete callbacks). + * + * @param array $route Route config. + * @param string $resource Resource name. + * @param string|null $prefix URL prefix (e.g. api/v1/). + */ + function route_api_resource(array &$route, string $resource, string $prefix = '') + { + $route[$prefix . $resource]['post'] = 'api/v1/' . $resource . '_api_v1/store'; + $route[$prefix . $resource . '/(:num)']['put'] = 'api/v1/' . $resource . '_api_v1/update/$1'; + $route[$prefix . $resource . '/(:num)']['delete'] = 'api/v1/' . $resource . '_api_v1/destroy/$1'; + $route[$prefix . $resource]['get'] = 'api/v1/' . $resource . '_api_v1/index'; + $route[$prefix . $resource . '/(:num)']['get'] = 'api/v1/' . $resource . '_api_v1/show/$1'; + } +}