public function testSubrouteMouting() { // Create Router $router = new \Bramus\Router\Router(); $router->mount('/movies', function () use($router) { $router->get('/', function () { echo 'overview'; }); $router->get('/(\\d+)', function ($id) { echo htmlentities($id); }); }); // Test the /movies route ob_start(); $_SERVER['REQUEST_URI'] = '/movies'; $router->run(); $this->assertEquals('overview', ob_get_contents()); // Test the /hello/bramus route ob_clean(); $_SERVER['REQUEST_URI'] = '/movies/1'; $router->run(); $this->assertEquals('1', ob_get_contents()); // Cleanup ob_end_clean(); }
} return $response; }); $router->post('/post/url', function () { $serviceName = filter_input(INPUT_POST, "sel-service"); $longUrl = filter_input(INPUT_POST, "longUrl"); if (isset($serviceName) && isset($longUrl)) { $key = file_get_contents("auth/key.txt"); $key = json_decode($key, true); if ($serviceName === "goo.gl") { $config = array('service-name' => $serviceName, 'longUrl' => $longUrl, 'apiKey' => $key[$serviceName]); } else { if ($serviceName === "bit.ly") { $config = array('service-name' => $serviceName, 'longUrl' => $longUrl, 'apiKey' => $key[$serviceName]["apiKey"], 'login' => $key[$serviceName]["login"]); } else { $config = array('service-name' => $serviceName, 'longUrl' => $longUrl); } } $bundle = new \peter\components\serviceBundle\serviceBundle($config); echo json_encode($bundle->sendReq()); } else { echo "Oops ! no data input"; } }); $router->set404(function () { header('HTTP/1.1 404 Not Found'); // ... do something special here echo file_get_contents("404.html"); }); $router->run();