public function testRequestUri() { $_SERVER['REQUEST_URI'] = '/foo'; $this->request = new Request(); $this->assertEquals('/foo', $this->request->getRawRequestUri()); unset($_SERVER['REQUEST_URI']); $this->request = new Request(); $this->assertEquals('/', $this->request->getRawRequestUri()); $this->assertEquals('/', $this->request->getRequestUri()); $_SERVER['REQUEST_URI'] = '/?foo=bar'; $this->request = new Request(); $this->assertEquals('/?foo=bar', $this->request->getRawRequestUri()); $_SERVER['REQUEST_URI'] = '/?foo=bar'; $this->request = new Request(); $this->assertEquals('/', $this->request->getRequestUri()); }
/** * Run the application. */ public function run() { if (empty($this->packagesMetadata)) { $this->setup(); if (empty($this->packagesMetadata)) { // @codeCoverageIgnoreStart $e = new PackagesNotFoundException('Application has no packages.'); $e->setAdditionalData('Application Path', $this->appDirectory); $this->error($e); return; // @codeCoverageIgnoreEnd } } $this->router = new Router(); $this->router->setRoutes($this->routes); $this->router->setMethod($this->request->getRequestMethod()); $this->router->setPath($this->request->getRequestUri()); $this->router->setIp($this->request->getClientIp()); try { $route = $this->router->getRoute(); } catch (RouteNotFoundException $e) { $this->notFound($e); return; } $middleware = false; if ($this->hasMiddleware()) { $middleware = new MiddlewareProcessor($this->config['Middleware']); } $package = $this->getPackage($route['package']); $runnable = $route['runnable']; $runnables = explode('::', $runnable); // Check if it's a view script only. if ($route['view.directRender'] === true) { try { if ($middleware) { $middleware->runBefore($this->request, $this->response); } $view = $this->getViewFor($package['package_name'], $runnables[0], $runnables[1]); if ($route['view.layout'] !== false) { $view->setLayout($route['view.layout']); } $view->setResponse($this->response); $view->render(); if ($middleware) { $middleware->runAfter(); } return; // @codeCoverageIgnoreStart } catch (\Exception $e) { $this->error($e); return; } } $classString = $package['namespace'] . '\\src\\' . $runnables[0]; if (class_exists($classString)) { try { if ($middleware) { $middleware->runBefore($this->request, $this->response); } $instance = $this->getRunnable($package['package_name'], $runnables[0], $runnables[1], $classString); if (is_callable(array($instance, $runnables[1]))) { if ($route['view.layout'] !== false) { $instance->getView()->setLayout($route['view.layout']); } call_user_func_array(array($instance, $runnables[1]), $route['params']); $instance->finalise(); if ($middleware) { $middleware->runAfter(); } return; } // @codeCoverageIgnoreStart } catch (\Exception $e) { $this->error($e); return; } $this->notFound(new RunnableNotFoundException('No such runnable: ' . $classString . '::' . $runnables[1])); } $this->notFound(new RunnableNotFoundException('No such runnable: ' . $classString . '::' . $runnables[1])); }