Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix module reserved routes #2013

Open
wants to merge 1 commit into
base: 1.9/develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions classes/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,8 @@ public static function unload($module)
// load and add the module routes
$module_routes = \Fuel::load($path);

$route_names = array();
foreach($module_routes as $name => $_route)
{
if ($name === '_root_')
{
$name = $module;
}
elseif (strpos($name, $module.'/') !== 0 and $name != $module and $name !== '_404_')
{
$name = $module.'/'.$name;
}

$route_names[] = $name;
};
$routes = \Router::parse_module_routes($module_routes, $module);
$route_names = array_keys($routes);

// delete the defined module routes
\Router::delete($route_names);
Expand Down
23 changes: 1 addition & 22 deletions classes/request.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,28 +280,7 @@ public function __construct($uri, $route = true, $method = null)
// load and add the module routes
$module_routes = \Fuel::load($module_path);

$reserve_routes = array(
'_root_' => $module,
'_403_' => '_403_',
'_404_' => '_404_',
'_500_' => '_500_',
$module => $module,
);

$prepped_routes = array();
foreach($module_routes as $name => $_route)
{
if (isset($reserve_routes[$name]))
{
$name = $reserve_routes[$name];
}
elseif (strpos($name, $module.'/') !== 0)
{
$name = $module.'/'.$name;
}

$prepped_routes[$name] = $_route;
};
$prepped_routes = \Router::parse_module_routes($module_routes, $module);

// update the loaded list of routes
\Router::add($prepped_routes, null, true);
Expand Down
36 changes: 36 additions & 0 deletions classes/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,42 @@ public static function delete($path, $case_sensitive = null)
}
}

/**
* It parses the module routes
*
* @param array $module_routes
* @param string $module_name
* @return array
* @see Fuel\Core\Request::__construct, Fuel\Core\Module::unload
*/
public static function parse_module_routes(array $module_routes, $module_name)
{
$routes = array();

foreach ($module_routes as $name => $path)
{
if ($name === '_root_')
{
$name = $module_name;
}

// Exception routings. Redundant condition for short-circuit evaluation
elseif ($name[0] === '_' and preg_match('/\A_(4|5)\d{2}_\z/', $name)) {
// do nothing
}

// Add if there is no module name
elseif (strpos($name, $module_name . '/') !== 0 and $name !== $module_name)
{
$name = $module_name . '/' . $name;
}

$routes[$name] = $path;
};

return $routes;
}

/**
* Processes the given request using the defined routes
*
Expand Down