/** * Add a route for error handling * @param string $errorType the type of error to route * @param string $actionName used to define the action to route to */ public function routeError($errorType, $actionName) { if (true === is_numeric($errorType)) { $errorRouteId = $this->routeId[$errorType]; } elseif (class_exists($errorType) && is_subclass_of($errorType, '\\Exception')) { $errorRouteId = preg_replace('/\\W/', '', self::ERROR_CUSTOM_ROUTE_ID . $errorType); $this->customErrorRoutes[] = $errorType; $this->routeId[$errorType] = $errorRouteId; } else { throw new Exception('Unable to add error route for %s', 0, $errorType); } $this->_router->any($errorRouteId, array('as' => $errorRouteId, 'to' => $actionName)); return $this; }
exit('The application environment is not set correctly.'); } } //initiate config new \core\config(); //create alias for Router use core\router, helpers\url; //define routes Router::any('admin', '\\controllers\\admin\\admin@index'); Router::any('admin/login', '\\controllers\\admin\\auth@login'); Router::any('admin/logout', '\\controllers\\admin\\auth@logout'); Router::any('admin/users', '\\controllers\\admin\\users@index'); Router::any('admin/users/add', '\\controllers\\admin\\users@add'); Router::any('admin/users/edit/(:num)', '\\controllers\\admin\\users@edit'); Router::any('admin/posts', '\\controllers\\admin\\posts@index'); Router::any('admin/posts/add', '\\controllers\\admin\\posts@add'); Router::any('admin/posts/edit/(:num)', '\\controllers\\admin\\posts@edit'); Router::any('admin/posts/delete/(:num)', '\\controllers\\admin\\posts@delete'); Router::any('admin/cats', '\\controllers\\admin\\cats@index'); Router::any('admin/cats/add', '\\controllers\\admin\\cats@add'); Router::any('admin/cats/edit/(:num)', '\\controllers\\admin\\cats@edit'); Router::any('admin/cats/delete/(:num)', '\\controllers\\admin\\cats@delete'); Router::any('', '\\controllers\\blog@index'); Router::any('category/(:any)', '\\controllers\\blog@cat'); Router::any('(:any)', '\\controllers\\blog@post'); //if no route found Router::error('\\core\\error@index'); //turn on old style routing Router::$fallback = false; //execute matched routes Router::dispatch();
/** * @group issues * @ticket 37 **/ public function test_optional_parameter_in_class_routes() { $r = new Router(); $r->any('/optional/*', 'Respect\\Rest\\MyOptionalParamRoute'); $response = $r->dispatch('get', '/optional')->response(); $this->assertEquals('John Doe', (string) $response); }
Router::any('applications', '\\controllers\\applications@create'); Router::any('locations', '\\controllers\\locations@create'); Router::any('apply', '\\controllers\\apply@index'); Router::any('apply_submit', '\\controllers\\apply@submit'); Router::any('changepassword', '\\controllers\\changepassword@index'); Router::any('changepassword_submit', '\\controllers\\changepassword@submit'); Router::any('registerBoardMember', '\\controllers\\registerAdmin@index'); Router::any('registerBoardMember_submit', '\\controllers\\registerAdmin@submit'); Router::any('draftBoard', '\\controllers\\draftBoard@index'); Router::any('draftBoard_wishlist', '\\controllers\\draftBoard@wishlist'); Router::any('draftBoard_search', '\\controllers\\draftBoard@search'); Router::any('draftBoard_main', '\\controllers\\draftBoard@draftBoard'); Router::any('trip_analytics', '\\controllers\\trip_analytics@create'); Router::any('application_analytics', '\\controllers\\application_analytics@create'); //ajax routes Router::any('ajax/applicantSearch', '\\controllers\\ajax@applicantSearch'); Router::any('ajax/applicantAnswers', '\\controllers\\ajax@applicantAnswers'); Router::any('ajax/checkTurn', '\\controllers\\ajax@checkTurn'); Router::any('ajax/draft', '\\controllers\\ajax@draft'); Router::any('ajax/updateTurn', '\\controllers\\ajax@updateTurn'); Router::any('ajax/getDrafted', '\\controllers\\ajax@getDrafted'); Router::any('ajax/startDraft', '\\controllers\\ajax@beginDraft'); Router::any('ajax/finalizeDraft', '\\controllers\\ajax@finalizeDraft'); Router::any('ajax/getDraftOrder', '\\controllers\\ajax@getDraftOrder'); //if no route found Router::error('\\core\\error@index'); //turn on old style routing Router::$fallback = false; //execute matched routes Router::dispatch(); // debugger
<?php Router::any('/', 'HomeController:index'); // // Default hook routes. // Router::mount('/', 'Hook\\Application\\Routes');
function test_single_last_param2() { $r = new Router(); $args = array(); $r->any('/documents/**', function ($documentsPath) use(&$args) { $args = func_get_args(); }); $r->dispatch('get', '/documents/foo/bar')->response(); $this->assertEquals(array(array('foo', 'bar')), $args); }
Router::any('admin/cities/add', '\\controllers\\admin\\cities@add'); Router::any('admin/cities/edit/(:num)', '\\controllers\\admin\\cities@edit'); Router::any('admin/cities/delete/(:num)', '\\controllers\\admin\\cities@delete'); Router::any('admin/permissions', '\\controllers\\admin\\permissions@index'); Router::any('admin/permissions/add', '\\controllers\\admin\\permissions@add'); Router::any('admin/permissions/edit/(:num)', '\\controllers\\admin\\permissions@edit'); Router::any('admin/permissions/delete/(:num)', '\\controllers\\admin\\permissions@delete'); Router::any('admin/archive', '\\controllers\\admin\\archive@index'); Router::any('admin/search', '\\controllers\\admin\\search@index'); Router::any('admin/pick', '\\controllers\\admin\\pick@index'); Router::any('admin/root', '\\controllers\\admin\\root@index'); Router::any('admin/root/add', '\\controllers\\admin\\root@add'); Router::any('admin/root/edit/(:num)', '\\controllers\\admin\\root@edit'); Router::any('admin/root/delete/(:num)', '\\controllers\\admin\\root@delete'); Router::any('admin/login', '\\controllers\\admin\\auth@login'); Router::any('admin/logout', '\\controllers\\admin\\auth@logout'); Router::any('', '\\controllers\\orders@index'); Router::any('/view/(:num)', '\\controllers\\orders@view'); Router::any('/edit/(:num)', '\\controllers\\orders@edit'); Router::any('search', '\\controllers\\search@index'); Router::any('pick', '\\controllers\\pick@index'); Router::any('faq', '\\controllers\\faq@index'); Router::any('message/send', '\\controllers\\orders@send_message'); Router::any('login', '\\controllers\\auth@login'); Router::any('logout', '\\controllers\\auth@logout'); //if no route found Router::error('\\core\\error@index'); //turn on old style routing Router::$fallback = false; //execute matched routes Router::dispatch();
/** * Unit test for Commit: 3e8d536 * * Catchall route called with / only would not get passed a parameter * to the callback function. */ function test_catchall_on_root_call_should_get_callback_parameter() { $r = new Router(); $args = array(); $r->any('/**', function ($documentsPath) use(&$args) { $args = func_get_args(); }); $r->dispatch('get', '/')->response(); $this->assertTrue(\is_array($args[0])); }
Router::get(['/image/{params}/{imagePath}', 'rules' => ['imagePath' => '[/\\a-z0-9_-]+', 'params' => '[a-z0-9-]+'], 'as' => 'imagefly'], 'Ivliev\\Imagefly\\ImageflyController@getIndex'); Router::get(['/{page?}', 'rules' => ['page' => '[a-z0-9_-]+'], 'as' => 'front.page'], 'Front\\Pages@getPage'); /** * Ajax */ /** * Тесты */ Router::get(['/Test', 'as' => 'front.test'], 'Front\\Pages@getTest'); Router::get(['/ImageTest/{imagePath}', 'rules' => ['imagePath' => '[/\\a-z0-9_-]+'], 'as' => 'front.test.image'], 'Test\\Imagefly@getImageTest'); Router::get(['/ImageTest2', 'as' => 'front.image.2'], 'Test\\Imagefly@getTest2'); Router::get(['/ImageTest3', 'as' => 'front.image.3'], 'Test\\Imagefly@getTest3'); Router::any(['/TestLang', 'as' => 'test.lang'], 'Test\\I18nTest@anyLang'); Router::any(['/Tests', 'as' => 'test.index'], 'Test\\I18nTest@anyIndex'); Router::any(['/TestLangRoute', 'as' => 'test.langroute'], 'Test\\I18nTest@anyTestLangRoute'); Router::any(['/TestNestedSets', 'as' => 'test.nestedsets'], 'Test\\NestedSets@anyIndex'); Router::any(['/TestFaker', 'as' => 'test.faker'], 'Test\\FakerTest@anyIndex'); Router::any(['/TestFaker2', 'as' => 'test.faker2'], 'Test\\FakerTest@anyIndex2'); Router::any(['/TestWord', 'as' => 'test.word'], 'Test\\WordTranslate@anyIndex'); Router::any(['/TestWidget', 'as' => 'test.widget'], 'Test\\Widget@anyIndex'); Router::any(['/TestLangChange', 'rules' => ['page' => '[a-z0-9_-]+'], 'as' => 'test.lang.change'], 'Test\\I18nTest@anyChangeLang'); Router::any(['/TestQuiz', 'rules' => ['id' => '[0-9]+'], 'as' => 'test.quiz.change'], 'Test\\Quiz\\Test@anyIndex'); Router::any(['/TestQuizResult', 'rules' => ['id' => '[0-9]+'], 'as' => 'test.result'], 'Test\\Quiz\\Test@anyResult'); //Router::get(['/test', 'as' => 'front.getTest'],'Front\Main@getTest'); //Router::any(['/test2', 'as' => 'front.anyTest'],'Front\Main@anyTest2'); //Router::get(['/API/Mobile/JSON/V1/confirmFriendship', 'as' => 'confirmFriendship'],'Api\Mobile\JSON\V1\Greeting@postConfirmFriendship'); Router::any(['/viewTest', 'as' => 'test.viewTests.index'], 'Test\\ViewTests@anyIndex'); Router::any(['/withLayout', 'as' => 'test.viewTests.WithLayout'], 'Test\\ViewTests@anyWithLayout'); Router::any(['/users/{id?}', 'rules' => ['id' => '[0-9]+'], 'as' => 'test.routeTests.users'], 'Test\\RouteTests@anyContents'); Router::any(['/users/list/{status?}/{page?}', 'rules' => ['status' => '[a-zа-я]+', 'page' => '[0-9]+'], 'as' => 'test.routeTests.usersList'], 'Test\\RouteTests@anyUsersList');
Router::any(['/Admin/Articles/Edit/{id?}', 'rules' => ['id' => '[0-9]+'], 'as' => 'back.articles.edit'], 'Back\\Articles@anyEdit'); Router::get(['/Admin/Articles/Delete/{id?}', 'rules' => ['id' => '[0-9]+'], 'as' => 'back.articles.delete'], 'Back\\Articles@getDelete'); Router::get(['/Admin/Categories', 'as' => 'back.categories.list'], 'Back\\Categories@getList'); //Router::any(['/Admin/Categories/Add', 'as' => 'back.categories.add'],'Back\Categories@anyAdd'); Router::any(['/Admin/Categories/Save', 'as' => 'back.categories.save'], 'Back\\Categories@anySaveSorting'); Router::any(['/Admin/Categories/Edit/{id?}', 'rules' => ['id' => '[0-9]+'], 'as' => 'back.categories.edit'], 'Back\\Categories@anyEdit'); Router::get(['/Admin/Entities', 'as' => 'back.entities.list'], 'Back\\Entities@getList'); Router::any(['/Admin/Entities/Add', 'as' => 'back.entities.add'], 'Back\\Entities@anyAdd'); Router::any(['/Admin/Entities/Edit/{id?}', 'rules' => ['id' => '[0-9]+'], 'as' => 'back.entities.edit'], 'Back\\Entities@anyEdit'); Router::get(['/Admin/Entities/Delete/{id?}', 'rules' => ['id' => '[0-9]+'], 'as' => 'back.entities.delete'], 'Back\\Entities@getDelete'); Router::get(['/Admin/Languages', 'as' => 'back.languages.list'], 'Back\\Languages@getList'); Router::any(['/Admin/Languages/Add', 'as' => 'back.languages.add'], 'Back\\Languages@anyAdd'); Router::any(['/Admin/Languages/Edit/{id?}', 'rules' => ['id' => '[0-9]+'], 'as' => 'back.languages.edit'], 'Back\\Languages@anyEdit'); Router::get(['/Admin/Languages/Delete/{id?}', 'rules' => ['id' => '[0-9]+'], 'as' => 'back.languages.delete'], 'Back\\Languages@getDelete'); Router::post(['/Admin/Languages/Image/Delete', 'as' => 'back.languages.image.delete'], 'Back\\Languages@postImageDelete'); Router::get(['/Admin/Settings', 'as' => 'back.settings'], 'Back\\Settings@getGroups'); Router::get(['/Admin/Settings/{alias?}', 'rules' => ['status' => '[a-zA-Z]+'], 'as' => 'back.settings.list'], 'Back\\Settings@getList'); Router::any(['/Admin/Settings/Edit/{id?}', 'rules' => ['id' => '[0-9]+'], 'as' => 'back.settings.edit'], 'Back\\Settings@anyEdit'); Router::get(['/Admin/Menus/List/{id?}', 'rules' => ['id' => '[0-9]+'], 'as' => 'back.menus.list'], 'Back\\Menus@getList'); Router::any(['/Admin/Menus/Save', 'as' => 'back.menus.save'], 'Back\\Menus@anySaveSorting'); Router::any(['/Admin/Menus/Add/{id?}', 'as' => 'back.menus.add'], 'Back\\Menus@anyAdd'); Router::any(['/Admin/Menus/Edit/{id?}', 'rules' => ['id' => '[0-9]+'], 'as' => 'back.menus.edit'], 'Back\\Menus@anyEdit'); Router::get(['/Admin/Menus/Delete/{id?}', 'rules' => ['id' => '[0-9]+'], 'as' => 'back.menus.delete'], 'Back\\Menus@getDelete'); Router::post(['/Admin/Menus/Image/Delete', 'as' => 'back.menus.image.delete'], 'Back\\Menus@postImageDelete'); Router::any(['/Admin/Quiz', 'as' => 'back.quiz'], 'Back\\Quiz@anyIndex'); Router::get(['/Admin/Team/List/{id?}', 'rules' => ['id' => '[0-9]+'], 'as' => 'back.teams.list'], 'Back\\Teams@getList'); Router::any(['/Admin/Player/Add/{id?}', 'rules' => ['id' => '[0-9]+'], 'as' => 'back.player.add'], 'Back\\Players@anyAdd'); Router::any(['/Admin/Player/Edit/{id?}', 'rules' => ['id' => '[0-9]+'], 'as' => 'back.player.edit'], 'Back\\Players@anyEdit'); /** * Тесты */