Skip to content

Commit

Permalink
Add http verb support for each module routing
Browse files Browse the repository at this point in the history
  • Loading branch information
N3Cr0N committed Feb 4, 2019
1 parent 3a4c630 commit 5c5862f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions third_party/MX/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '<')) {
Expand Down Expand Up @@ -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
Expand All @@ -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)) {
Expand Down

0 comments on commit 5c5862f

Please sign in to comment.