/** * Set the request data * * @param DispatcherRequestInterface $request */ public function receive(DispatcherRequestInterface $request) { if ($request->getContentType() == 'application/x-www-form-urlencoded') { if (in_array($request->getMethod(), array('PUT', 'DELETE', 'PATCH'))) { parse_str($request->getContent(), $data); $request->getData()->add($data); } } if (in_array($request->getContentType(), array('application/json', 'application/x-json', 'application/vnd.api+json'))) { if (in_array($request->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH'))) { $data = array(); if ($content = $request->getContent()) { $data = json_decode($content, true); } if ($data) { $request->getData()->add($data); } // Transform the JSON API request payloads if ($request->getContentType() == 'application/vnd.api+json') { if (is_array($request->data->data)) { $data = $request->data->data; if (isset($data['attributes']) && is_array($data['attributes'])) { $request->data->add($data['attributes']); } } } } } }
/** * Receive request * * @param DispatcherRequestInterface $request */ public function receive(DispatcherRequestInterface $request) { //Set document root for IIS if (!isset($_SERVER['DOCUMENT_ROOT'])) { if (isset($_SERVER['SCRIPT_FILENAME'])) { $_SERVER['DOCUMENT_ROOT'] = str_replace('\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0 - strlen($_SERVER['PHP_SELF']))); } if (isset($_SERVER['PATH_TRANSLATED'])) { $_SERVER['DOCUMENT_ROOT'] = str_replace('\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0 - strlen($_SERVER['PHP_SELF']))); } } //When using PHP-FPM HTTP_AUTHORIZATION is called REDIRECT_HTTP_AUTHORIZATION if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) { $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION']; } //Set the version if (isset($_SERVER['SERVER_PROTOCOL']) && strpos($_SERVER['SERVER_PROTOCOL'], '1.0') !== false) { $request->setVersion('1.0'); } }
/** * Receive request * * @param DispatcherRequestInterface $request */ public function receive(DispatcherRequestInterface $request) { //Set the headers $headers = array(); foreach ($_SERVER as $key => $value) { if ($value && strpos($key, 'HTTP_') === 0) { // Cookies are handled using the $_COOKIE superglobal if (strpos($key, 'HTTP_COOKIE') === 0) { continue; } $headers[substr($key, 5)] = $value; } elseif ($value && strpos($key, 'CONTENT_') === 0) { $name = substr($key, 8); // Content- $name = 'Content-' . ($name == 'MD5' ? $name : ucfirst(strtolower($name))); $headers[$name] = $value; } } $request->getHeaders()->add($headers); }