loadRoutes example

// Simulate having a blank session         $_SESSION                  = [];
        $_SERVER['REQUEST_METHOD'] = $method;

        $request = $this->setupRequest($method$path);
        $request = $this->setupHeaders($request);
        $request = $this->populateGlobals($method$request$params);
        $request = $this->setRequestBody($request$params);

        // Initialize the RouteCollection         if ($routes = $this->routes) {
            $routes = Services::routes()->loadRoutes();
        }

        $routes->setHTTPVerb($method);

        // Make sure any other classes that might call the request         // instance get the right one.         Services::injectMock('request', $request);

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

        
$sortByHandler = array_key_exists('h', $params);
        $host          = $params['host'] ?? null;

        // Set HTTP_HOST         if ($host) {
            $request              = Services::request();
            $_SERVER              = $request->getServer();
            $_SERVER['HTTP_HOST'] = $host;
            $request->setGlobal('server', $_SERVER);
        }

        $collection = Services::routes()->loadRoutes();

        // Reset HTTP_HOST         if ($host) {
            unset($_SERVER['HTTP_HOST']);
        }

        $methods = [
            'get',
            'head',
            'post',
            'patch',
            
CLI::write(' Usage: ' . $this->usage);
            CLI::write('Example: filter:check get /');
            CLI::write(' filter:check put products/1');

            return EXIT_ERROR;
        }

        $method = strtolower($params[0]);
        $route  = $params[1];

        // Load Routes         Services::routes()->loadRoutes();

        $filterCollector = new FilterCollector();

        $filters = $filterCollector->get($method$route);

        // PageNotFoundException         if ($filters['before'] === ['<unknown>']) {
            CLI::error(
                "Can't find a route: " .
                CLI::color(
                    '"' . strtoupper($method) . ' ' . $route . '"',
                    


// Load environment settings from .env files into $_SERVER and $_ENV require_once SYSTEMPATH . 'Config/DotEnv.php';

$env = new DotEnv(ROOTPATH);
$env->load();

// Always load the URL helper, it should be used in most of apps. helper('url');

Services::routes()->loadRoutes();
// Create our own Request and Response so we can         // use the same ones for Filters and FilterInterface         // yet isolate them from outside influence         $this->request ??= clone Services::request();
        $this->response ??= clone Services::response();

        // Create our config and Filters instance to reuse for performance         $this->filtersConfig ??= config(FiltersConfig::class);
        $this->filters ??= new Filters($this->filtersConfig, $this->request, $this->response);

        if ($this->collection === null) {
            $this->collection = Services::routes()->loadRoutes();
        }

        $this->doneFilterSetUp = true;
    }

    // --------------------------------------------------------------------     // Utility     // --------------------------------------------------------------------
    /** * Returns a callable method for a filter position * using the local HTTP instances. * * @param FilterInterface|string $filter The filter instance, class, or alias * @param string $position "before" or "after" */
// Simulate having a blank session         $_SESSION                  = [];
        $_SERVER['REQUEST_METHOD'] = $method;

        $request = $this->setupRequest($method$path);
        $request = $this->setupHeaders($request);
        $request = $this->populateGlobals($method$request$params);
        $request = $this->setRequestBody($request);

        // Initialize the RouteCollection         if ($routes = $this->routes) {
            $routes = Services::routes()->loadRoutes();
        }

        $routes->setHTTPVerb($method);

        // Make sure any other classes that might call the request         // instance get the right one.         Services::injectMock('request', $request);

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

        

    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();

        
Home | Imprint | This part of the site doesn't use cookies.