public function testDelete() { $_SERVER['REQUEST_METHOD'] = 'DELETE'; $_SERVER['REQUEST_URI'] = '/test'; $t = false; Router::delete('/test', function () use(&$t) { $t = true; return false; })->process(); $this->assertTrue($t); }
public function testMethods() { $router = new Router(); $this->assertFalse($router->has("home")); $this->assertNull($router->get("home")); $this->assertSame(0, $router->count()); // add one $this->assertInstanceOf("SugiPHP\\Routing\\Router", $router->add("home", new Route("/"))); $this->assertSame(1, $router->count()); $this->assertTrue($router->has("home")); $this->assertInstanceOf("SugiPHP\\Routing\\Route", $router->get("home")); // change it $this->assertInstanceOf("SugiPHP\\Routing\\Router", $router->set("home", new Route("/foo"))); $this->assertSame(1, $router->count()); $this->assertTrue($router->has("home")); $this->assertInstanceOf("SugiPHP\\Routing\\Route", $router->get("home")); // remove it $this->assertInstanceOf("SugiPHP\\Routing\\Router", $router->delete("home")); $this->assertFalse($router->has("home")); $this->assertNull($router->get("home")); $this->assertSame(0, $router->count()); }
Router::setContentType('application/json'); Router::setStatus(200, 'OK'); die(json_encode(array('status'=>'OK', 'data'=>array('user_id'=>$params[1], 'username'=>'neogeek')))); }); // curl -X PUT -d "email=neo@neo-geek.net" http://example.com/examples/router/user/1 $app->put('/user/:int', function ($params) { Router::setContentType('application/json'); Router::setStatus(200, 'OK'); parse_str(file_get_contents('php://input'), $_PUT); die(json_encode(array('status'=>'OK', 'data'=>array('user_id'=>$params[1], 'username'=>'neogeek', 'email'=>$_PUT['email'])))); }); // curl -X DELETE http://example.com/examples/router/user/1 $app->delete('/user/:int', function ($params) { Router::setContentType('application/json'); Router::setStatus(200, 'OK'); die(json_encode(array('status'=>'OK', 'data'=>array()))); });
<?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']); }
/** * Unloads a module from the stack. * * @param string $module The module name * @return void */ public static function unload($module) { // delete all routes for this module \Router::delete($module . '/(:any)'); unset(static::$modules[$module]); }
public function test_add_route_and_router_option_name() { $path = 'testing/route'; $name = 'option_name'; $options = array('name' => $name); $prepend = false; $case_sensitive = null; Router::add($path, $options, $prepend, $case_sensitive); $this->assertEquals($path, Router::$routes[$name]->path); $this->assertEquals($name, Router::$routes[$name]->name); Router::delete($name); }
/** * Unloads a module from the stack. * * @param string $module The module name * @return void */ public static function unload($module) { // we can only unload a loaded module if (isset(static::$modules[$module])) { $path = static::$modules[$module]; if (is_file($path .= 'config/routes.php')) { // 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; } // delete the defined module routes \Router::delete($route_names); } } // delete this module unset(static::$modules[$module]); }
} $entry = $folder . "/" . $subfolder . "/" . $entry; $newwhitelist = $config->get("whitelist"); if (!in_array($entry, $newwhitelist)) { $newwhitelist[] = $entry; $config->set("whitelist", $newwhitelist); } echo json_encode(array("code" => "200")); }); $router->delete('/api/whitelist/:entry', function ($entry) use($auth, $config, $session) { if (!$auth->isConnected()) { header("Location: " . ROOT . "login"); die; } $newwhitelist = $config->get("whitelist"); foreach ($newwhitelist as $i => $item) { if ($item == $entry) { array_splice($newwhitelist, $i, 1); } } $config->set("whitelist", $newwhitelist); echo json_encode(array("code" => "200")); }); $router->delete('/api/whitelist/:folder/:entry', function ($folder, $entry) use($auth, $config, $session) { if (!$auth->isConnected()) { header("Location: " . ROOT . "login"); die; } $entry = $folder . "/" . $entry; $newwhitelist = $config->get("whitelist"); foreach ($newwhitelist as $i => $item) { if ($item == $entry) {
if ($_GET['section'] == "insert_reset_auto_assign_hash") { $router_data = Router_old::getRouterInfo($_GET['router_id']); if (permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, (int) $router_data['user_id'])) { $insert_result = RouterEditor::resetRouterAutoAssignHash($_GET['router_id']); header('Location: ./routereditor.php?section=edit&router_id=' . $_GET['router_id']); } else { Permission::denyAccess(PERM_ROOT, (int) $router_data['user_id']); } } if ($_GET['section'] == "insert_delete") { $router = new Router((int) $_GET['router_id']); $router->fetch(); //Root and owning user can delete router if (permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, $router->getUserId())) { if ($_POST['really_delete'] == 1) { if ($router->delete()) { $message[] = array("Der Router " . $router->getHostname() . " wurde entfernt.", 1); Message::setMessage($message); header('Location: ./user.php?user_id=' . $_SESSION['user_id']); } else { $message[] = array("Der Router konnte nicht entfernt werden.", 2); Message::setMessage($message); header('Location: ./routereditor.php?section=edit&router_id=' . $_GET['router_id']); } } else { $message[] = array("Zum löschen des Routers ist eine Bestätigung erforderlich!", 2); Message::setMessage($message); header('Location: ./routereditor.php?section=edit&router_id=' . $_GET['router_id']); } } else { Permission::denyAccess(PERM_ROOT, (int) $router_data['user_id']);