/** * Runs the application * * This method gets the correct route for the current request and runs the callback of the route * * @param \CodeCollab\Http\Request\Request $request The current request */ public function run(Request $request) { $dispatcher = $this->router->getDispatcher(); $routeInfo = $dispatcher->dispatch($request->server('REQUEST_METHOD'), $request->server('REQUEST_URI_PATH')); switch ($routeInfo[0]) { case Dispatcher::NOT_FOUND: $routeInfo = $this->getNotFoundRoute($dispatcher); break; case Dispatcher::METHOD_NOT_ALLOWED: $routeInfo = $this->runMethodNotAllowed($dispatcher); break; case Dispatcher::FOUND: break; } $response = $this->runRoute($routeInfo); $response->send(); }
/** * @covers CodeCollab\Http\Request\Request::__construct * @covers CodeCollab\Http\Request\Request::processServerVariables * @covers CodeCollab\Http\Request\Request::server */ public function testServerWithProtocol() { $request = new Request($this->createMock(Decryptor::class), $this->baseRequestData['server'], $this->baseRequestData['get'], $this->baseRequestData['post'], $this->baseRequestData['files'], $this->baseRequestData['cookies'], $this->baseRequestData['input']); $this->assertSame('1.1', $request->server('SERVER_PROTOCOL')); }
*/ if (php_sapi_name() === 'cli') { return; } /** * Setup decryptor */ $decryptor = new Decryptor(file_get_contents(__DIR__ . '/encryption.key')); /** * Setup the request object */ $request = new Request($decryptor, $_SERVER, $_GET, $_POST, $_FILES, $_COOKIE, file_get_contents('php://input')); /** * Setup the session */ $session = new Session('/', $request->server('SERVER_NAME'), $request->isEncrypted()); /** * Setup authentication object */ $user = new User($session); /** * Setup the router */ $routeCache = $user->isLoggedIn() ? '/cache/routes-authenticated.php' : '/cache/routes.php'; $routeCollector = new RouteCollector(new RouteParser(), new RouteDataGenerator()); $router = new Router($routeCollector, function ($dispatchData) { return new RouteDispatcher($dispatchData); }, __DIR__ . $routeCache, !$production); /** * Load routes */