/** * {@inheritdoc} */ public static function fromGlobals(array $server = null, array $query = null, array $body = null, array $cookies = null, array $files = null) { $server = static::normalizeServer($server ?: $_SERVER); $files = static::normalizeFiles($files ?: $_FILES); $headers = static::marshalHeaders($server); $request = new ServerRequest($server, $files, static::marshalUriFromServer($server, $headers), static::get('REQUEST_METHOD', $server, 'GET'), 'php://input', $headers); $contentType = current($request->getHeader('Content-Type')); $input = file_get_contents('php://input'); // support header like "application/json" and "application/json; charset=utf-8" if ($contentType !== false && stristr($contentType, 'application/json')) { $data = (array) json_decode($input); } else { switch ($request->getMethod()) { case 'POST': $data = $_POST; break; default: parse_str($input, $data); break; } } return $request->withCookieParams($cookies ?: $_COOKIE)->withQueryParams($query ?: $_GET)->withParsedBody($body ?: $data); }
/** * Returns true if a JSON-RCP request has been received. * * @return boolean */ public function isJsonRpc(Request $request) { $method = $request->getMethod(); $type = $request->getHeader('content-type'); return $method === 'POST' && !empty($type[0]) && strpos($type[0], 'application/json') !== false; }