/** * 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 * @covers CodeCollab\Http\Request\Request::matches */ public function testMatchesDoesNotMatch() { $request = new Request($this->createMock(Decryptor::class), array_merge($this->baseRequestData['server'], ['REQUEST_URI' => '/foo/bar']), $this->baseRequestData['get'], $this->baseRequestData['post'], $this->baseRequestData['files'], $this->baseRequestData['cookies'], $this->baseRequestData['input']); $this->assertFalse($request->startsWith('/foo/xbar')); }
/** * Handles the cookie login * * @param \CodeCollab\Http\Request\Request $request The request object * @param \CodeCollab\Authentication\Authentication $user The authentication object * * @return \Symfony\Component\HttpFoundation\Response The HTTP response */ public function doCookieLogin(Request $request, Authentication $user) : Response { // Hardcoded user info. Normally this would be retrieved from the database. // This contains a user with username + password of demo + demo. $userInfo = ['username' => 'demo', 'name' => 'Demo Demo', 'hash' => '$2y$14$hPOMx1/RiQHriUVLgst0mOiZj1CyE7ziXk9LNf3UgZxsNuST.xnpe']; if ($request->cookie('rememberme') !== 'enabled' || !$user->logInRememberMe($userInfo)) { $this->response->addCookie('rememberme', '', (new \DateTime())->sub(new \DateInterval('P30D'))); } else { $this->response->addCookie('rememberme', '', (new \DateTime())->add(new \DateInterval('P30D'))); } $this->response->setStatusCode(StatusCode::FOUND); $this->response->addHeader('Location', $request->getBaseUrl()); return $this->response; }
*/ require_once __DIR__ . '/init.deployment.php'; /** * Prevent further execution when on CLI */ 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);