From 5c5862f6362ac38ee1c3f694901a9f1160bfda0e Mon Sep 17 00:00:00 2001 From: N3Cr0N Date: Mon, 4 Feb 2019 04:00:45 +0100 Subject: [PATCH] Add http verb support for each module routing --- third_party/MX/Modules.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/third_party/MX/Modules.php b/third_party/MX/Modules.php index bf65cfa..a32fc5b 100644 --- a/third_party/MX/Modules.php +++ b/third_party/MX/Modules.php @@ -116,7 +116,6 @@ public static function load($module) /* create or return an existing controller from the registry */ if (!isset(self::$registry[$alias])) { - // Backward function // Before PHP 7.1.0, list() only worked on numerical arrays and assumes the numerical indices start at 0. if (version_compare(phpversion(), '7.1', '<')) { @@ -282,8 +281,7 @@ public static function parse_routes($module, $uri) { /* load the route file */ if (! isset(self::$routes[$module])) { - - // Backward function + // Backward function // Before PHP 7.1.0, list() only worked on numerical arrays and assumes the numerical indices start at 0. if (version_compare(phpversion(), '7.1', '<')) { // php version isn't high enough @@ -301,8 +299,22 @@ public static function parse_routes($module, $uri) return; } + // Add http verb support for each module routing + $http_verb = isset($_SERVER['REQUEST_METHOD']) ? strtolower($_SERVER['REQUEST_METHOD']) : 'cli'; + /* parse module routes */ foreach (self::$routes[$module] as $key => $val) { + // Add http verb support for each module routing + if (is_array($val)) { + $val = array_change_key_case($val, CASE_LOWER); + + if (isset($val[$http_verb])) { + $val = $val[$http_verb]; + } else { + continue; + } + } + $key = str_replace(array(':any', ':num'), array('.+', '[0-9]+'), $key); if (preg_match('#^'.$key.'$#', $uri)) {