Change syntax for specifying multiple routes for the same action

This commit is contained in:
Kijin Sung 2020-06-13 00:37:59 +09:00
parent b706f2f6ab
commit 1bf5b4c240
2 changed files with 12 additions and 16 deletions

View file

@ -108,22 +108,19 @@ class ModuleActionParser
// Parse routes. // Parse routes.
$route = trim($action['route']); $route = trim($action['route']);
$method = trim($action['method']); $method = trim($action['method']);
$route_vars = []; $route_arg = [];
if ($route) if ($route)
{ {
$route_info = self::analyzeRoute($route); $methods = $method ? explode('|', strtoupper($method)) : (starts_with('proc', $action_name) ? ['POST'] : ['GET']);
$route_vars = $route_info->vars; $routes = explode_with_escape('|', $route);
if ($method) foreach ($routes as $route)
{ {
$methods = explode('|', strtoupper($method)); $route_info = self::analyzeRoute($route);
} $route_arg[$route] = $route_info->vars;
else foreach ($methods as $method)
{ {
$methods = starts_with('proc', $action_name) ? ['POST'] : ['GET']; $info->route->{$method}[$route_info->regexp] = $action_name;
} }
foreach ($methods as $method)
{
$info->route->{$method}[$route_info->regexp] = $action_name;
} }
} }
@ -133,8 +130,7 @@ class ModuleActionParser
$action_info->grant = trim($action['grant']) ?: 'guest'; $action_info->grant = trim($action['grant']) ?: 'guest';
$action_info->ruleset = trim($action['ruleset']); $action_info->ruleset = trim($action['ruleset']);
$action_info->method = $method; $action_info->method = $method;
$action_info->route = $route; $action_info->route = $route_arg;
$action_info->route_vars = $route_vars;
$action_info->standalone = trim($action['standalone']) === 'false' ? 'false' : 'true'; $action_info->standalone = trim($action['standalone']) === 'false' ? 'false' : 'true';
$action_info->check_csrf = (trim($action['check_csrf']) ?: trim($action['check-csrf'])) === 'false' ? 'false' : 'true'; $action_info->check_csrf = (trim($action['check_csrf']) ?: trim($action['check-csrf'])) === 'false' ? 'false' : 'true';
$action_info->meta_noindex = (trim($action['meta_noindex']) ?: trim($action['meta-noindex'])) === 'true' ? 'true' : 'false'; $action_info->meta_noindex = (trim($action['meta_noindex']) ?: trim($action['meta-noindex'])) === 'true' ? 'true' : 'false';

View file

@ -57,7 +57,7 @@
</grants> </grants>
<actions> <actions>
<action name="dispBoardContent" type="view" permission="list" standalone="false" index="true" /> <action name="dispBoardContent" type="view" permission="list" standalone="false" index="true" />
<action name="dispBoardWrite" type="view" permission="write_document" standalone="false" meta-noindex="true" route="write(/$document_srl)?" /> <action name="dispBoardWrite" type="view" permission="write_document" standalone="false" meta-noindex="true" route="write|edit/$document_srl" />
<action name="dispBoardDelete" type="view" permission="write_document" standalone="false" meta-noindex="true" route="delete/$document_srl" /> <action name="dispBoardDelete" type="view" permission="write_document" standalone="false" meta-noindex="true" route="delete/$document_srl" />
<action name="dispBoardWriteComment" type="view" permission="write_comment" standalone="false" meta-noindex="true" route="comment/write/$document_srl" /> <action name="dispBoardWriteComment" type="view" permission="write_comment" standalone="false" meta-noindex="true" route="comment/write/$document_srl" />
<action name="dispBoardReplyComment" type="view" permission="write_comment" standalone="false" meta-noindex="true" route="comment/reply/$comment_srl"/> <action name="dispBoardReplyComment" type="view" permission="write_comment" standalone="false" meta-noindex="true" route="comment/reply/$comment_srl"/>