router example


    protected function tryToRouteIt(?RouteCollectionInterface $routes = null)
    {
        if ($routes === null) {
            $routes = Services::routes()->loadRoutes();
        }

        // $routes is defined in Config/Routes.php         $this->router = Services::router($routes$this->request);

        $path = $this->determinePath();

        $this->benchmark->stop('bootstrap');
        $this->benchmark->start('routing');

        $this->outputBufferingStart();

        $this->controller = $this->router->handle($path);
        $this->method     = $this->router->methodName();

        
/** * Finds filters. */
final class FilterFinder
{
    private Router $router;
    private Filters $filters;

    public function __construct(?Router $router = null, ?Filters $filters = null)
    {
        $this->router  = $router ?? Services::router();
        $this->filters = $filters ?? Services::filters();
    }

    private function getRouteFilters(string $uri): array
    {
        $this->router->handle($uri);

        $multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
        if ($multipleFiltersEnabled) {
            $filter = $this->router->getFilter();

            
$ipCheckEnabled = (bool) $app->config('check.ip');
    if ($ipCheckEnabled && !Utils::isAllowed($clientIp)) {
        $app->view()->setData('filePath', UPDATE_PATH . '/allowed_ip.txt');

        $app->render('noaccess.php');
        $app->response()->status(403);
        $app->stop();
    }

    // Redirect to "done" page if file cleanup was done     if (false && isset($_SESSION['CLEANUP_DONE']) && $app->router()->getCurrentRoute()->getName() !== 'done') {
        $url = $app->urlFor('done');
        $app->response()->redirect($url);
    } elseif (isset($_SESSION['DB_DONE']) && !isset($_SESSION['CLEANUP_DONE']) && $app->router()->getCurrentRoute()->getName() !== 'cleanup') {
        $url = $app->urlFor('cleanup');
        $app->response()->redirect($url);
    }
});

$app->error(function DException $e) use ($app) {
    if (!$app->request()->isAjax()) {
        throw $e;
    }
$response = $this->app
            ->setContext('web')
            ->setRequest($request)
            ->run($routes, true);

        $output = \ob_get_contents();
        if (empty($response->getBody()) && ! empty($output)) {
            $response->setBody($output);
        }

        // Reset directory if it has been set         Services::router()->setDirectory(null);

        // Ensure the output buffer is identical so no tests are risky         while (\ob_get_level() > $buffer) {
            \ob_end_clean(); // @codeCoverageIgnore         }

        while (\ob_get_level() < $buffer) {
            \ob_start(); // @codeCoverageIgnore         }

        return new FeatureResponse($response);
    }

    protected $title = 'Routes';

    /** * Returns the data of this collector to be formatted in the toolbar * * @throws ReflectionException */
    public function display(): array
    {
        $rawRoutes = Services::routes(true);
        $router    = Services::router(null, null, true);

        // Get our parameters         // Closure routes         if (is_callable($router->controllerName())) {
            $method = new ReflectionFunction($router->controllerName());
        } else {
            try {
                $method = new ReflectionMethod($router->controllerName()$router->methodName());
            } catch (ReflectionException $e) {
                // If we're here, the method doesn't exist                 // and is likely calculated in _remap.
        Services::injectMock('filters', Services::filters(null, false));

        // Make sure validation is reset between tests         Services::injectMock('validation', Services::validation(null, false));

        $response = $this->app
            ->setContext('web')
            ->setRequest($request)
            ->run($routes, true);

        // Reset directory if it has been set         Services::router()->setDirectory(null);

        return new TestResponse($response);
    }

    /** * Performs a GET request. * * @param string $path URI path relative to baseURL. May include query. * * @return TestResponse * * @throws RedirectException * @throws Exception */
Home | Imprint | This part of the site doesn't use cookies.