Exemple #1
0
 /**
  * Builds and returns the HTML needed to fill a tab to display
  * within the Debug Bar
  *
  * @return string
  */
 public function display() : string
 {
     $routes = Services::routes(true);
     $router = Services::router(null, true);
     $output = "<h3>Matched Route</h3>";
     $output .= "<table><tbody>";
     if ($match = $router->getMatchedRoute()) {
         $output .= "<tr><td>{$match[0]}</td>";
         $output .= "<td>{$match[1]}</td></tr>";
     }
     $output .= "<tr><td>Directory:</td><td>" . htmlspecialchars($router->directory()) . "</td></tr>";
     $output .= "<tr><td>Controller:</td><td>" . htmlspecialchars($router->controllerName()) . "</td></tr>";
     $output .= "<tr><td>Method:</td><td>" . htmlspecialchars($router->methodName()) . "</td></tr>";
     $output .= "<tr><td>Params:</td><td>" . print_r($router->params(), true) . "</td></tr>";
     $output .= "</table></tbody>";
     $output .= "<h3>Defined Routes</h3>";
     $output .= "<table><tbody>";
     $routes = $routes->getRoutes();
     foreach ($routes as $from => $to) {
         $output .= "<tr>";
         $output .= "<td>" . htmlspecialchars($from) . "</td>";
         $output .= "<td>" . htmlspecialchars($to) . "</td>";
         $output .= "</tr>";
     }
     $output .= "</tbody></table>";
     return $output;
 }
 /**
  * Try to Route It - As it sounds like, works with the router to
  * match a route against the current URI. If the route is a
  * "redirect route", will also handle the redirect.
  *
  * @param RouteCollectionInterface $routes  An collection interface to use in place
  *                                          of the config file.
  */
 protected function tryToRouteIt(RouteCollectionInterface $routes = null)
 {
     if (empty($routes) || !$routes instanceof RouteCollectionInterface) {
         require APPPATH . 'Config/Routes.php';
     }
     // $routes is defined in Config/Routes.php
     $this->router = Services::router($routes);
     $path = is_cli() ? $this->request->getPath() : $this->request->uri->getPath();
     $this->benchmark->stop('bootstrap');
     $this->benchmark->start('routing');
     ob_start();
     $this->controller = $this->router->handle($path);
     $this->method = $this->router->methodName();
     $this->benchmark->stop('routing');
 }
 public function testRun404OverrideByClosure()
 {
     $_SERVER['argv'] = ['index.php', '/'];
     $_SERVER['argc'] = 2;
     // Inject mock router.
     $routes = new RouteCollection();
     $routes->setAutoRoute(false);
     $routes->set404Override(function () {
         echo '404 Override by Closure.';
     });
     $router = Services::router($routes);
     Services::injectMock('router', $router);
     ob_start();
     $this->codeigniter->run($routes);
     $output = ob_get_clean();
     $this->assertContains('404 Override by Closure.', $output);
 }