public function testMatchingCheckesMethod() { $this->setExpectedException('Vexillum\\Http\\PageNotFoundException'); $route = Router::post('/apath', function () { }); Router::run('GET', 'localboat.dev', '/apath'); }
public function testPost() { $_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_URI'] = '/test'; $t = false; Router::post('/test', function () use(&$t) { $t = true; return false; })->process(); $this->assertTrue($t); }
/** * @covers Zepto\Router::routes() */ public function testRoutes() { $this->router->get('/get', function () { return 'This is a get route'; }); $this->router->post('/post', function () { return 'This is a post route'; }); $routes = $this->router->routes(); $this->assertArrayHasKey('GET', $routes); $this->assertArrayHasKey('#^/get/$#', $routes['GET']); $this->assertInstanceOf('Zepto\\Route', $routes['GET']['#^/get/$#']); $this->assertArrayHasKey('POST', $routes); $this->assertArrayHasKey('#^/post/$#', $routes['POST']); $this->assertInstanceOf('Zepto\\Route', $routes['POST']['#^/post/$#']); }
}); $router->get('login', function () use($auth, $config, $session) { if (!$config->isInitialized()) { header("Location: " . ROOT . "install"); } if ($auth->isConnected()) { header("Location: " . ROOT); } else { require "template/login.php"; } }); $router->post('login', function () use($auth, $config, $session) { if ($auth->login($_POST["email"], $_POST["pass"])) { $session->setFlash("info", "Connexion réussie"); header("Location: " . ROOT); } else { $session->setFlash("info", "Identifiants incorrects"); } require "template/login.php"; }); $router->get('install', function () use($auth, $config, $session) { if ($config->isInitialized()) { header("Location: " . ROOT); die; } require "template/install.php"; }); $router->post('install', function () use($auth, $config, $session) { if ($config->isInitialized()) { header("Location: " . ROOT); die;
<?php namespace App\Controller; Router::get('/', "PrincipalController@index"); Router::get('professor', "ProfessorController@index"); Router::get('atividade', "AtividadeController@index"); Router::get('coordenador', "CoordenadorController@index"); Router::get('login', "UserController@index"); Router::post('login', "UserController@login"); Router::get('logout', "UserController@logout"); /* Router::get('other/@nome/@email', function($nome, $email){ echo $nome." - ".$email; }); */
<?php require_once 'Core' . DIRECTORY_SEPARATOR . 'config.php'; require_once 'Core' . DIRECTORY_SEPARATOR . 'autoload.php'; use Core\Config\Autoload; Autoload::load($load); $router = new Router(); $router->get('/', 'PageController::index'); /* Ajax */ $router->post('/connect', 'MemberController::connect'); $router->post('/chatroom', 'MemberController::get_chat_room'); $router->post('/notif', 'MessageController::get_notif'); $router->post('/chatroom/name', 'MemberController::get_chat_name'); $router->post('/contact/add', 'MemberController::add_contact'); $router->post('/message/last', 'MessageController::get_last_message'); $router->post('/message/new', 'MessageController::get_new_message'); $router->post('/message/send', 'MessageController::send'); $router->add_404('PageController::route_404'); $router->run();
<?php $r = new Router($app, $ds); $r->get('/', 'IndexController'); $r->get('/workout', 'WorkoutScheduleController'); $r->get('/workout/:id', 'WorkoutController'); $r->post('/workout/:id', 'WorkoutController'); $r->get('/stats', 'WorkoutLogController'); $r->get('/login', 'LoginController'); $r->post('/login', 'LoginController'); $r->get('/logout', 'LogoutController'); $r->post('/logout', 'LogoutController'); $r->get('/help', 'LoadTemplateController', 'help.php'); $r->get('/tos', 'LoadTemplateController', 'tos.php'); $r->get('/about', 'LoadTemplateController', 'about.php'); $admin_middleware = new AdminMiddleware($app); $r->group('/admin', function ($r) { $r->get('/', 'admin\\IndexController'); $r->get('/new-customer', 'admin\\NewCustomerController'); $r->get('/new-workout/:user_id', 'admin\\NewWorkoutController'); }); //, $admin_middleware); unset($r); unset($admin_middleware);
<?php require 'app/core/autoloader.php'; //define routes Router::get('', 'welcome@index'); Router::get('admin', 'admin@admin'); Router::get('admin/login', 'admin@login'); Router::post('admin/login', 'admin@login'); Router::get('admin/logout', 'admin@logout'); //if no route found Router::error('error@index'); //execute matched routes Router::dispatch(); ob_flush();
<?php require_once 'Core' . DIRECTORY_SEPARATOR . 'config.php'; require_once 'Core' . DIRECTORY_SEPARATOR . 'autoload.php'; use Core\Config\Autoload; Autoload::load($load); $router = new Router(); $router->get('/', 'PageController::index'); $router->get('/jeu', 'JeuController::index'); $router->post('/jeu/end', 'JeuController::save'); $router->post('/jeu/inscription', 'JeuController::inscription'); $router->get('/mail/{id}/{cle}', 'JeuController::mail'); $router->get('/date', 'DateController::get_date'); /* ADMIN */ $router->get('/admin', 'AdminController::login'); $router->post('/admin', 'AdminController::connexion'); $router->get('/admin/logout', 'AdminController::logout'); $router->get('/admin/dashboard', 'AdminController::classement'); $router->get('/admin/classement', 'AdminController::classement'); $router->get('/admin/joueurs', 'AdminController::info_joueur'); $router->post('/admin/joueurs/edit/{id}', 'AdminController::save_joueur'); $router->post('/admin/joueurs/add', 'AdminController::add_joueur'); $router->post('/admin/joueurs/remove/{id}', 'AdminController::remove_joueur'); $router->get('/admin/galerie', 'AdminController::galerie'); $router->post('/admin/galerie/edit/{id}', 'AdminController::save_photo'); $router->post('/admin/galerie/add', 'AdminController::add_photo'); $router->post('/admin/galerie/remove/{id}', 'AdminController::remove_photo'); $router->get('/admin/partenaire', 'AdminController::partenaire'); $router->post('/admin/partenaire/edit/{id}', 'AdminController::save_partenaire'); $router->post('/admin/partenaire/add', 'AdminController::add_partenaire'); $router->post('/admin/partenaire/remove/{id}', 'AdminController::remove_partenaire');
<?php $route = new Router(); //GET ROUTES //pages $route->get(URL . '/', ['PagesController', 'index']); $route->get(URL . '/dns-list', ['DnsController', 'dnsList']); //auth $route->get(URL . '/login', ['AuthController', 'login']); $route->get(URL . '/register', ['AuthController', 'register']); $route->get(URL . '/profile', ['AuthController', 'profile']); $route->get(URL . '/logout', ['AuthController', 'logout']); //management $route->get(URL . '/addDomainNameSystem', ['DnsController', 'addDomainNameSystem']); $route->get(URL . '/dns_edit', ['DnsController', 'editDomainNameSystem']); $route->get(URL . '/dns_delete', ['DnsController', 'deleteDomainNameSystem']); $route->get(URL . '/downloadFile', ['DnsController', 'downloadDnsZoneFile']); //POST ROUTES //auth $route->post(URL . '/loginPOST', ['AuthController', 'login_POST']); $route->post(URL . '/registerPOST', ['AuthController', 'register_POST']); $route->post(URL . '/profilePOST', ['AuthController', 'editProfile_POST']); ///management $route->post(URL . '/addDomainNameSystemPOST', ['DnsController', 'addDomainNameSystem_POST']); $route->post(URL . '/editDomainNameSystemPOST', ['DnsController', 'editDomainNameSystem_POST']); //create zones file $route->post(URL . '/createDnsZoneFile', ['DnsController', 'createDnsZoneFile']);
<?php Router::getInstance(); Router::get('', 'HomeController@index'); Router::get('a-propos', 'PagesController@about'); Router::get('soumettre', 'SubmitController@index'); Router::post('soumettre', 'SubmitController@submit'); Router::get('questions', 'ListController@recent'); Router::get('p', 'QuoteController@single'); Router::get('phrases', 'QuoteController@index'); Router::_404('ErrorController@_404');
<?php require_once 'Core' . DIRECTORY_SEPARATOR . 'config.php'; require_once 'Core' . DIRECTORY_SEPARATOR . 'autoload.php'; use Core\Config\Autoload; Autoload::load($load); $router = new Router(); $router->get('/', 'PageController::index'); $router->get('/create', 'GameController::create'); $router->post('/game', 'GameController::game'); $router->add_404('PageController::route_404'); $router->run();
<?php require_once 'Core' . DIRECTORY_SEPARATOR . 'config.php'; require_once 'Core' . DIRECTORY_SEPARATOR . 'autoload.php'; use Core\Config\Autoload; Autoload::load($load); $router = new Router(); $router->get('/', 'PageController::index'); $router->get('/create', 'GameController::get_create'); $router->post('/create', 'GameController::post_create'); $router->get('/join', 'GameController::get_join'); $router->post('/join', 'GameController::post_join'); $router->post('/game', 'GameController::get_game'); $router->post('/players', 'GameController::get_players'); $router->post('/narrator', 'GameController::get_narrator'); $router->get('/chat', 'PageController::chat'); $router->post('/new', 'MessageController::get_new_message'); $router->post('/send', 'MessageController::send_message'); $router->post('/last', 'MessageController::get_last_message'); $router->post('/contact', 'MessageController::get_contact'); $router->post('/notif', 'MessageController::get_notification'); $router->add_404('PageController::route_404'); $router->run();
<?php Router::post("/signin", array("controller" => "AuthController", "method" => "signin")); Router::post("/signup", array("controller" => "AuthController", "method" => "signup")); Router::post("/signout", array("controller" => "AuthController", "signout" => "signout")); # VALID POST REQUESTS Router::post("/", array("controller" => "TestController", "method" => "post_test"));
protected function post($regex, $callback) { Router::post($regex, $callback); }
<?php require 'app/core/autoloader.php'; //define routes Router::get('', 'welcome@index'); Router::get('admin', 'admin@admin'); Router::get('admin/login', 'admin@login'); Router::post('admin/login', 'admin@login'); Router::get('admin/logout', 'admin@logout'); Router::get('contacts', 'contacts@contacts'); Router::get('contacts/add', 'contacts@add'); Router::post('contacts/add', 'contacts@add'); Router::get('contacts/edit/(:num)', 'contacts@edit'); Router::post('contacts/edit/(:num)', 'contacts@edit'); Router::get('contacts/delete/(:num)', 'contacts@delete'); //if no route found Router::error('error@index'); //execute matched routes Router::dispatch(); ob_flush();
<?php require_once 'Core' . DIRECTORY_SEPARATOR . 'config.php'; require_once 'Core' . DIRECTORY_SEPARATOR . 'autoload.php'; use Core\Config\Autoload; Autoload::load($load); $router = new Router(); $router->get('/code', 'PageController::code'); $router->get('/', 'PageController::score'); $router->get('/search/{name}', 'PhpController::search'); $router->get('/top/{number}', 'PhpController::top'); $router->post('/code', 'PhpController::compile'); $router->add_404('PageController::route_404'); $router->run();
use Swagger\Annotations as SWG; /** * @SWG\Resource(resourcePath="/logs", * @SWG\Partial("log_create"), * @SWG\Partial("log_read") * ) */ /** * @SWG\Api( * path="/", * @SWG\Operation( * method="GET", * nickname="logidx", * @SWG\Partial("logs.index") * ) * ) */ Router::get('/', 'Operations@getStuff'); /** * @SWG\Api( * path="/", * @SWG\Operation( * method="POST", * nickname="newlog", * @SWG\Partial("logs.index") * ) * ) */ Router::post('/', 'Operation@postStuff');
/**USER ROUTES**/ Router::get('user/profile', 'user@profil'); Router::post('user/profile', 'user@profil'); Router::get('user', 'user@index'); Router::get('user/courts', 'user@courts'); Router::get('user/courts/create', 'user@addcourt'); Router::post('user/courts/create', 'user@addcourt'); Router::get('user/courts/edit/(:num)', 'user@editcourt'); Router::post('user/courts/edit/(:num)', 'user@editcourt'); Router::get('user/courts/delete/(:num)', 'user@deletecourt'); Router::get('user/tours', 'user@tours'); Router::post('user/tours', 'user@tours'); Router::get('user/tours/(:num)', 'user@teams'); Router::post('user/tours/(:num)', 'user@teams'); Router::get('user/tours/createteam/(:num)', 'user@createteam'); Router::post('user/tours/createteam/(:num)', 'user@createteam'); Router::get('user/tours/jointeam/(:num)', 'user@jointeam'); Router::post('user/tours/jointeam/(:num)', 'user@jointeam'); /**ADMIN ROUTES**/ Router::get('admin', 'admin@index'); Router::get('admin/profil', 'admin@profil'); Router::post('admin/profil', 'admin@profil'); Router::get('admin/staffs', 'admin@staffs'); Router::get('admin/staffs/create', 'admin@addstaff'); Router::post('admin/staffs/create', 'admin@addstaff'); Router::get('admin/staffs/delete/(:num)', 'admin@deletestaff'); //if no route found Router::error('error@index'); //execute matched routes Router::dispatch(); ob_flush();
<?php /* Set cache configuration */ $cache_callback = ['class' => 'Modules\\Cache\\CacheModule', 'method' => 'save']; $router = new Router($cache_callback); $router->get('/', 'HomeController'); /* Admin routes */ $router->datas('/admin', 'AdminController'); $router->datas('/admin/login', 'AdminController', 'login'); $router->get('/admin/logout', 'AdminController', 'logout'); $router->get('/admin/users', 'AdminController', 'users'); $router->datas('/admin/add_admin', 'AdminController', 'add_admin'); $router->datas('/admin/modules', 'AdminController', 'modules'); $router->get('/admin/modules/:module', 'AdminController', 'module_infos'); $router->post('/admin/modules/edit', 'AdminController', 'module_edit'); /* Others */ $router->get('/json', 'HomeController', 'json'); $router->get('/contact', 'ContactController'); $router->get('/infos', 'InfosController'); $router->get('/user', 'UserController'); $router->get('/user/:name', 'UserController'); $router->get('/security', 'SecurityController'); //$router->add('POST', '/user/:name', 'UserController', 'post'); //$router->add('POST', '/user/:name/json', 'UserController', 'post_json'); if (empty($_GET['r'])) { $route = '/'; } else { $route = '/' . $_GET['r']; } $method = strtoupper($_SERVER["REQUEST_METHOD"]); /* If cache is enabled */
<?php //Include Config files. include 'app/config/routes.php'; include 'app/config/paths.php'; //Initialize Autoloader. include 'app/system/autoloader.php'; autoloader::register(); //Initialize the router with URL and route config file. $router = new Router($routes, $_GET['url']); switch ($_SERVER['REQUEST_METHOD']) { case 'GET': $router->get($_GET['url']); break; case 'POST': $router->post($_GET['url']); break; case 'PUT': //need to be done $router->put($_GET['url']); break; case 'DELETE': //need to be done $router->delete($_GET['url']); break; default: die('not a valid Request Method, request method =' . $_SERVER['REQUEST_METHOD']); }
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'); /** * Тесты */