/** * Get the cookie. * * @param string $key * @param null|mixed $default * @return mixed */ public function getCookie($key, $default = null) { $cookies = $this->request->getCookieParams(); return $cookies && isset($cookies[$key]) ? $cookies[$key] : $default; }
/** * Run the app. * * @param bool|false $silent if true, just return response object * @return \Psr\Http\Message\ResponseInterface * @throws Exception */ public function run($silent = false) { $env = new Environment($_SERVER); $this->currentApp = $this->getCurrentApp($env); $request = Request::createFromEnvironment($env); $request = $request->withAttribute('currentApp', $this->currentApp); // set default headers $headers = new Headers(array()); // set default response $response = new Response(200, $headers); try { $response = $this->process($request, $response); } catch (Exception $ex) { error_log('[run] Exception ' . $ex->getCode() . ' ' . $ex->getMessage() . "\n" . $ex->getTraceAsString()); $response = $this->handleException($ex, $request, $response); } if (!$silent) { $this->respond($response); } return $response; }