Move constants from Routing to Router

This commit is contained in:
Visman 2020-07-01 23:37:14 +07:00
parent 8eb4b6ea9c
commit a228dc1792
3 changed files with 85 additions and 85 deletions

View file

@ -40,7 +40,7 @@ class Install
$this->c->user = $this->c->users->create(['id' => 2, 'group_id' => $this->c->GROUP_ADMIN]);
$r = $this->c->Router;
$r->add(['GET', 'POST'], '/install', 'Install:install', 'Install');
$r->add($r::DUO, '/install', 'Install:install', 'Install');
$method = $_SERVER['REQUEST_METHOD'];

View file

@ -7,10 +7,6 @@ use ForkBB\Models\Page;
class Routing
{
const DUO = ['GET', 'POST'];
const GET = 'GET';
const PST = 'POST';
/**
* Контейнер
* @var Container
@ -41,32 +37,32 @@ class Routing
// регистрация/вход/выход
if ($user->isGuest) {
// вход
$r->add(self::DUO, '/login', 'Auth:login', 'Login');
$r->add($r::DUO, '/login', 'Auth:login', 'Login');
// забыли кодовую фразу
$r->add(self::DUO, '/login/forget', 'Auth:forget', 'Forget');
$r->add($r::DUO, '/login/forget', 'Auth:forget', 'Forget');
// смена кодовой фразы
$r->add(self::DUO, '/login/{id:\d+}/{key}/{hash}', 'Auth:changePass', 'ChangePassword');
$r->add($r::DUO, '/login/{id:\d+}/{key}/{hash}', 'Auth:changePass', 'ChangePassword');
// регистрация
if ('1' == $config->o_regs_allow) {
$r->add(self::GET, '/registration', 'Rules:confirmation', 'Register');
$r->add(self::PST, '/registration/agree', 'Register:reg', 'RegisterForm');
$r->add(self::GET, '/registration/activate/{id:\d+}/{key}/{hash}', 'Register:activate', 'RegActivate');
$r->add($r::GET, '/registration', 'Rules:confirmation', 'Register');
$r->add($r::PST, '/registration/agree', 'Register:reg', 'RegisterForm');
$r->add($r::GET, '/registration/activate/{id:\d+}/{key}/{hash}', 'Register:activate', 'RegActivate');
}
} else {
// выход
$r->add(self::GET, '/logout/{token}', 'Auth:logout', 'Logout');
$r->add($r::GET, '/logout/{token}', 'Auth:logout', 'Logout');
// обработка "кривых" перенаправлений с логина и регистрации
$r->add(self::GET, '/login[/{tail:.*}]', 'Redirect:toIndex');
$r->add(self::GET, '/registration[/{tail:.*}]', 'Redirect:toIndex');
$r->add($r::GET, '/login[/{tail:.*}]', 'Redirect:toIndex');
$r->add($r::GET, '/registration[/{tail:.*}]', 'Redirect:toIndex');
}
// просмотр разрешен
if ('1' == $user->g_read_board) {
// главная
$r->add(self::GET, '/', 'Index:view', 'Index');
$r->add(self::GET, '/index.php', 'Redirect:toIndex');
$r->add(self::GET, '/index.html', 'Redirect:toIndex');
$r->add($r::GET, '/', 'Index:view', 'Index');
$r->add($r::GET, '/index.php', 'Redirect:toIndex');
$r->add($r::GET, '/index.html', 'Redirect:toIndex');
// правила
if (
'1' == $config->o_rules
@ -75,96 +71,96 @@ class Routing
|| '1' == $config->o_regs_allow
)
) {
$r->add(self::GET, '/rules', 'Rules:view', 'Rules');
$r->add($r::GET, '/rules', 'Rules:view', 'Rules');
}
// поиск
if ('1' == $user->g_search) {
$r->add(self::GET, '/search[/simple/{keywords}[/{page:[1-9]\d*}]]', 'Search:view', 'Search');
$r->add(self::PST, '/search', 'Search:view');
$r->add($r::GET, '/search[/simple/{keywords}[/{page:[1-9]\d*}]]', 'Search:view', 'Search');
$r->add($r::PST, '/search', 'Search:view');
$r->add(self::GET, '/search/advanced[/{keywords}/{author}/{forums}/{serch_in:\d}/{sort_by:\d}/{sort_dir:\d}/{show_as:\d}[/{page:[1-9]\d*}]]', 'Search:viewAdvanced', 'SearchAdvanced');
$r->add(self::PST, '/search/advanced', 'Search:viewAdvanced');
$r->add($r::GET, '/search/advanced[/{keywords}/{author}/{forums}/{serch_in:\d}/{sort_by:\d}/{sort_dir:\d}/{show_as:\d}[/{page:[1-9]\d*}]]', 'Search:viewAdvanced', 'SearchAdvanced');
$r->add($r::PST, '/search/advanced', 'Search:viewAdvanced');
$r->add(self::GET, '/search[/user/{uid:[2-9]|[1-9]\d+}]/{action:(?!search)[a-z_]+}[/in_forum/{forum:[1-9]\d*}][/{page:[1-9]\d*}]', 'Search:action', 'SearchAction');
$r->add($r::GET, '/search[/user/{uid:[2-9]|[1-9]\d+}]/{action:(?!search)[a-z_]+}[/in_forum/{forum:[1-9]\d*}][/{page:[1-9]\d*}]', 'Search:action', 'SearchAction');
}
// юзеры
if ($user->viewUsers) {
// список пользователей
$r->add(self::GET, '/userlist[/{group:all|[1-9]\d*}/{sort:username|registered|num_posts}/{dir:ASC|DESC}/{name}][/{page:[1-9]\d*}]', 'Userlist:view', 'Userlist');
$r->add(self::PST, '/userlist', 'Userlist:view');
$r->add($r::GET, '/userlist[/{group:all|[1-9]\d*}/{sort:username|registered|num_posts}/{dir:ASC|DESC}/{name}][/{page:[1-9]\d*}]', 'Userlist:view', 'Userlist');
$r->add($r::PST, '/userlist', 'Userlist:view');
// юзеры
$r->add(self::GET, '/user/{id:[2-9]|[1-9]\d+}/{name}', 'ProfileView:view', 'User');
$r->add(self::DUO, '/user/{id:[2-9]|[1-9]\d+}/edit/profile', 'ProfileEdit:edit', 'EditUserProfile');
$r->add(self::DUO, '/user/{id:[2-9]|[1-9]\d+}/edit/config', 'ProfileConfig:config', 'EditUserBoardConfig');
$r->add(self::DUO, '/user/{id:[2-9]|[1-9]\d+}/edit/email', 'ProfileEmail:email', 'EditUserEmail');
$r->add(self::DUO, '/user/{id:[2-9]|[1-9]\d+}/edit/passphrase', 'ProfilePass:pass', 'EditUserPass');
$r->add(self::DUO, '/user/{id:[2-9]|[1-9]\d+}/edit/moderation', 'ProfileMod:moderation', 'EditUserModeration');
$r->add($r::GET, '/user/{id:[2-9]|[1-9]\d+}/{name}', 'ProfileView:view', 'User');
$r->add($r::DUO, '/user/{id:[2-9]|[1-9]\d+}/edit/profile', 'ProfileEdit:edit', 'EditUserProfile');
$r->add($r::DUO, '/user/{id:[2-9]|[1-9]\d+}/edit/config', 'ProfileConfig:config', 'EditUserBoardConfig');
$r->add($r::DUO, '/user/{id:[2-9]|[1-9]\d+}/edit/email', 'ProfileEmail:email', 'EditUserEmail');
$r->add($r::DUO, '/user/{id:[2-9]|[1-9]\d+}/edit/passphrase', 'ProfilePass:pass', 'EditUserPass');
$r->add($r::DUO, '/user/{id:[2-9]|[1-9]\d+}/edit/moderation', 'ProfileMod:moderation', 'EditUserModeration');
} elseif (! $user->isGuest) {
// только свой профиль
$r->add(self::GET, '/user/{id:' . $user->id . '}/{name}', 'ProfileView:view', 'User');
$r->add(self::DUO, '/user/{id:' . $user->id . '}/edit/profile', 'ProfileEdit:edit', 'EditUserProfile');
$r->add(self::DUO, '/user/{id:' . $user->id . '}/edit/config', 'ProfileConfig:config', 'EditUserBoardConfig');
$r->add(self::DUO, '/user/{id:' . $user->id . '}/edit/email', 'ProfileEmail:email', 'EditUserEmail');
$r->add(self::DUO, '/user/{id:' . $user->id . '}/edit/passphrase', 'ProfilePass:pass', 'EditUserPass');
$r->add($r::GET, '/user/{id:' . $user->id . '}/{name}', 'ProfileView:view', 'User');
$r->add($r::DUO, '/user/{id:' . $user->id . '}/edit/profile', 'ProfileEdit:edit', 'EditUserProfile');
$r->add($r::DUO, '/user/{id:' . $user->id . '}/edit/config', 'ProfileConfig:config', 'EditUserBoardConfig');
$r->add($r::DUO, '/user/{id:' . $user->id . '}/edit/email', 'ProfileEmail:email', 'EditUserEmail');
$r->add($r::DUO, '/user/{id:' . $user->id . '}/edit/passphrase', 'ProfilePass:pass', 'EditUserPass');
}
// смена своего email
if (! $user->isGuest) {
$r->add(self::GET, '/user/{id:' . $user->id . '}/{email}/{key}/{hash}', 'ProfileEmail:setEmail', 'SetNewEmail');
$r->add($r::GET, '/user/{id:' . $user->id . '}/{email}/{key}/{hash}', 'ProfileEmail:setEmail', 'SetNewEmail');
}
// пометка разделов прочитанными
if (! $user->isGuest) {
$r->add(self::GET, '/forum/{id:\d+}/markread/{token}', 'Misc:markread', 'MarkRead');
$r->add($r::GET, '/forum/{id:\d+}/markread/{token}', 'Misc:markread', 'MarkRead');
}
// разделы
$r->add(self::GET, '/forum/{id:[1-9]\d*}/{name}[/{page:[1-9]\d*}]', 'Forum:view', 'Forum' );
$r->add(self::DUO, '/forum/{id:[1-9]\d*}/new/topic', 'Post:newTopic', 'NewTopic');
$r->add($r::GET, '/forum/{id:[1-9]\d*}/{name}[/{page:[1-9]\d*}]', 'Forum:view', 'Forum' );
$r->add($r::DUO, '/forum/{id:[1-9]\d*}/new/topic', 'Post:newTopic', 'NewTopic');
// темы
$r->add(self::GET, '/topic/{id:[1-9]\d*}/{name}[/{page:[1-9]\d*}]', 'Topic:viewTopic', 'Topic' );
$r->add(self::GET, '/topic/{id:[1-9]\d*}/view/new', 'Topic:viewNew', 'TopicViewNew' );
$r->add(self::GET, '/topic/{id:[1-9]\d*}/view/unread', 'Topic:viewUnread', 'TopicViewUnread');
$r->add(self::GET, '/topic/{id:[1-9]\d*}/view/last', 'Topic:viewLast', 'TopicViewLast' );
$r->add(self::GET, '/topic/{id:[1-9]\d*}/new/reply[/{quote:[1-9]\d*}]', 'Post:newReply', 'NewReply' );
$r->add(self::PST, '/topic/{id:[1-9]\d*}/new/reply', 'Post:newReply' );
$r->add($r::GET, '/topic/{id:[1-9]\d*}/{name}[/{page:[1-9]\d*}]', 'Topic:viewTopic', 'Topic' );
$r->add($r::GET, '/topic/{id:[1-9]\d*}/view/new', 'Topic:viewNew', 'TopicViewNew' );
$r->add($r::GET, '/topic/{id:[1-9]\d*}/view/unread', 'Topic:viewUnread', 'TopicViewUnread');
$r->add($r::GET, '/topic/{id:[1-9]\d*}/view/last', 'Topic:viewLast', 'TopicViewLast' );
$r->add($r::GET, '/topic/{id:[1-9]\d*}/new/reply[/{quote:[1-9]\d*}]', 'Post:newReply', 'NewReply' );
$r->add($r::PST, '/topic/{id:[1-9]\d*}/new/reply', 'Post:newReply' );
// сообщения
$r->add(self::GET, '/post/{id:[1-9]\d*}#p{id}', 'Topic:viewPost', 'ViewPost' );
$r->add(self::DUO, '/post/{id:[1-9]\d*}/edit', 'Edit:edit', 'EditPost' );
$r->add(self::DUO, '/post/{id:[1-9]\d*}/delete', 'Delete:delete', 'DeletePost');
$r->add($r::GET, '/post/{id:[1-9]\d*}#p{id}', 'Topic:viewPost', 'ViewPost' );
$r->add($r::DUO, '/post/{id:[1-9]\d*}/edit', 'Edit:edit', 'EditPost' );
$r->add($r::DUO, '/post/{id:[1-9]\d*}/delete', 'Delete:delete', 'DeletePost');
// сигналы (репорты)
if (
! $user->isAdmin
&& ! $user->isGuest
) { // ????
$r->add(self::DUO, '/post/{id:[1-9]\d*}/report', 'Report:report', 'ReportPost');
$r->add($r::DUO, '/post/{id:[1-9]\d*}/report', 'Report:report', 'ReportPost');
}
}
// админ и модератор
if ($user->isAdmMod) {
$r->add(self::GET, '/admin/', 'AdminIndex:index', 'Admin');
$r->add(self::GET, '/admin/statistics', 'AdminStatistics:statistics', 'AdminStatistics');
$r->add($r::GET, '/admin/', 'AdminIndex:index', 'Admin');
$r->add($r::GET, '/admin/statistics', 'AdminStatistics:statistics', 'AdminStatistics');
if ($this->c->userRules->viewIP) {
$r->add(self::GET, '/admin/get/host/{ip:[0-9a-fA-F:.]+}', 'AdminHost:view', 'AdminHost');
$r->add(self::GET, '/admin/users/user/{id:[2-9]|[1-9]\d+}[/{page:[1-9]\d*}]', 'AdminUsersStat:view', 'AdminUserStat');
$r->add($r::GET, '/admin/get/host/{ip:[0-9a-fA-F:.]+}', 'AdminHost:view', 'AdminHost');
$r->add($r::GET, '/admin/users/user/{id:[2-9]|[1-9]\d+}[/{page:[1-9]\d*}]', 'AdminUsersStat:view', 'AdminUserStat');
}
$r->add(self::DUO, '/admin/users', 'AdminUsers:view', 'AdminUsers');
$r->add(self::DUO, '/admin/users/result/{data}[/{page:[1-9]\d*}]', 'AdminUsersResult:view', 'AdminUsersResult');
$r->add(self::DUO, '/admin/users/{action:\w+}/{ids:\d+(?:-\d+)*}[/{token}]', 'AdminUsersAction:view', 'AdminUsersAction');
$r->add($r::DUO, '/admin/users', 'AdminUsers:view', 'AdminUsers');
$r->add($r::DUO, '/admin/users/result/{data}[/{page:[1-9]\d*}]', 'AdminUsersResult:view', 'AdminUsersResult');
$r->add($r::DUO, '/admin/users/{action:\w+}/{ids:\d+(?:-\d+)*}[/{token}]', 'AdminUsersAction:view', 'AdminUsersAction');
$r->add(self::GET, '/admin/users/promote/{uid:[2-9]|[1-9]\d+}/{pid:[1-9]\d*}/{token}', 'AdminUsersPromote:promote', 'AdminUserPromote');
$r->add($r::GET, '/admin/users/promote/{uid:[2-9]|[1-9]\d+}/{pid:[1-9]\d*}/{token}', 'AdminUsersPromote:promote', 'AdminUserPromote');
if ($user->isAdmin) {
$r->add(self::DUO, '/admin/users/new', 'AdminUsersNew:view', 'AdminUsersNew');
$r->add($r::DUO, '/admin/users/new', 'AdminUsersNew:view', 'AdminUsersNew');
}
if ($this->c->userRules->banUsers) {
$r->add(self::DUO, '/admin/bans', 'AdminBans:view', 'AdminBans');
$r->add(self::DUO, '/admin/bans/new[/{ids:\d+(?:-\d+)*}[/{uid:[2-9]|[1-9]\d+}]]', 'AdminBans:add', 'AdminBansNew');
$r->add(self::DUO, '/admin/bans/edit/{id:[1-9]\d*}', 'AdminBans:edit', 'AdminBansEdit');
$r->add(self::GET, '/admin/bans/result/{data}[/{page:[1-9]\d*}]', 'AdminBans:result', 'AdminBansResult');
$r->add(self::GET, '/admin/bans/delete/{id:[1-9]\d*}/{token}[/{uid:[2-9]|[1-9]\d+}]', 'AdminBans:delete', 'AdminBansDelete');
$r->add($r::DUO, '/admin/bans', 'AdminBans:view', 'AdminBans');
$r->add($r::DUO, '/admin/bans/new[/{ids:\d+(?:-\d+)*}[/{uid:[2-9]|[1-9]\d+}]]', 'AdminBans:add', 'AdminBansNew');
$r->add($r::DUO, '/admin/bans/edit/{id:[1-9]\d*}', 'AdminBans:edit', 'AdminBansEdit');
$r->add($r::GET, '/admin/bans/result/{data}[/{page:[1-9]\d*}]', 'AdminBans:result', 'AdminBansResult');
$r->add($r::GET, '/admin/bans/delete/{id:[1-9]\d*}/{token}[/{uid:[2-9]|[1-9]\d+}]', 'AdminBans:delete', 'AdminBansDelete');
}
if (
@ -172,33 +168,33 @@ class Routing
|| '0' == $config->o_report_method
|| '2' == $config->o_report_method
) {
$r->add(self::GET, '/admin/reports', 'AdminReports:view', 'AdminReports');
$r->add(self::GET, '/admin/reports/zap/{id:[1-9]\d*}/{token}', 'AdminReports:zap', 'AdminReportsZap');
$r->add($r::GET, '/admin/reports', 'AdminReports:view', 'AdminReports');
$r->add($r::GET, '/admin/reports/zap/{id:[1-9]\d*}/{token}', 'AdminReports:zap', 'AdminReportsZap');
}
$r->add(self::PST, '/moderate', 'Moderate:action', 'Moderate');
$r->add($r::PST, '/moderate', 'Moderate:action', 'Moderate');
}
// только админ
if ($user->isAdmin) {
$r->add(self::GET, '/admin/statistics/info', 'AdminStatistics:info', 'AdminInfo' );
$r->add(self::DUO, '/admin/options', 'AdminOptions:edit', 'AdminOptions' );
$r->add(self::DUO, '/admin/permissions', 'AdminPermissions:edit', 'AdminPermissions' );
$r->add(self::DUO, '/admin/categories', 'AdminCategories:view', 'AdminCategories' );
$r->add(self::DUO, '/admin/categories/{id:[1-9]\d*}/delete', 'AdminCategories:delete', 'AdminCategoriesDelete');
$r->add(self::DUO, '/admin/forums', 'AdminForums:view', 'AdminForums' );
$r->add(self::DUO, '/admin/forums/new', 'AdminForums:edit', 'AdminForumsNew' );
$r->add(self::DUO, '/admin/forums/{id:[1-9]\d*}/edit', 'AdminForums:edit', 'AdminForumsEdit' );
$r->add(self::DUO, '/admin/forums/{id:[1-9]\d*}/delete', 'AdminForums:delete', 'AdminForumsDelete' );
$r->add(self::GET, '/admin/groups', 'AdminGroups:view', 'AdminGroups' );
$r->add(self::PST, '/admin/groups/default', 'AdminGroups:defaultSet', 'AdminGroupsDefault');
$r->add(self::PST, '/admin/groups/new[/{base:[1-9]\d*}]', 'AdminGroups:edit', 'AdminGroupsNew' );
$r->add(self::DUO, '/admin/groups/{id:[1-9]\d*}/edit', 'AdminGroups:edit', 'AdminGroupsEdit' );
$r->add(self::DUO, '/admin/groups/{id:[1-9]\d*}/delete', 'AdminGroups:delete', 'AdminGroupsDelete' );
$r->add(self::DUO, '/admin/censoring', 'AdminCensoring:edit', 'AdminCensoring' );
$r->add(self::DUO, '/admin/maintenance', 'AdminMaintenance:view', 'AdminMaintenance' );
$r->add(self::PST, '/admin/maintenance/rebuild', 'AdminMaintenance:rebuild', 'AdminMaintenanceRebuild');
$r->add(self::GET, '/admin/maintenance/rebuild/{token}/{clear:[01]}/{limit:[1-9]\d*}/{start:[1-9]\d*}', 'AdminMaintenance:rebuild', 'AdminRebuildIndex' );
$r->add($r::GET, '/admin/statistics/info', 'AdminStatistics:info', 'AdminInfo' );
$r->add($r::DUO, '/admin/options', 'AdminOptions:edit', 'AdminOptions' );
$r->add($r::DUO, '/admin/permissions', 'AdminPermissions:edit', 'AdminPermissions' );
$r->add($r::DUO, '/admin/categories', 'AdminCategories:view', 'AdminCategories' );
$r->add($r::DUO, '/admin/categories/{id:[1-9]\d*}/delete', 'AdminCategories:delete', 'AdminCategoriesDelete');
$r->add($r::DUO, '/admin/forums', 'AdminForums:view', 'AdminForums' );
$r->add($r::DUO, '/admin/forums/new', 'AdminForums:edit', 'AdminForumsNew' );
$r->add($r::DUO, '/admin/forums/{id:[1-9]\d*}/edit', 'AdminForums:edit', 'AdminForumsEdit' );
$r->add($r::DUO, '/admin/forums/{id:[1-9]\d*}/delete', 'AdminForums:delete', 'AdminForumsDelete' );
$r->add($r::GET, '/admin/groups', 'AdminGroups:view', 'AdminGroups' );
$r->add($r::PST, '/admin/groups/default', 'AdminGroups:defaultSet', 'AdminGroupsDefault');
$r->add($r::PST, '/admin/groups/new[/{base:[1-9]\d*}]', 'AdminGroups:edit', 'AdminGroupsNew' );
$r->add($r::DUO, '/admin/groups/{id:[1-9]\d*}/edit', 'AdminGroups:edit', 'AdminGroupsEdit' );
$r->add($r::DUO, '/admin/groups/{id:[1-9]\d*}/delete', 'AdminGroups:delete', 'AdminGroupsDelete' );
$r->add($r::DUO, '/admin/censoring', 'AdminCensoring:edit', 'AdminCensoring' );
$r->add($r::DUO, '/admin/maintenance', 'AdminMaintenance:view', 'AdminMaintenance' );
$r->add($r::PST, '/admin/maintenance/rebuild', 'AdminMaintenance:rebuild', 'AdminMaintenanceRebuild');
$r->add($r::GET, '/admin/maintenance/rebuild/{token}/{clear:[01]}/{limit:[1-9]\d*}/{start:[1-9]\d*}', 'AdminMaintenance:rebuild', 'AdminRebuildIndex' );
}

View file

@ -11,6 +11,10 @@ class Router
const METHOD_NOT_ALLOWED = 405;
const NOT_IMPLEMENTED = 501;
const DUO = ['GET', 'POST'];
const GET = 'GET';
const PST = 'POST';
/**
* Массив постоянных маршрутов
* @var array