Source of file RequestFactory.php
Size: 1,811 Bytes - Last Modified: 2017-11-08T13:54:24+00:00
/home/travis/build/bluzphp/framework/src/Request/RequestFactory.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 | <?php /** * Bluz Framework Component * * @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ declare(strict_types=1); namespace Bluz\Request; use Bluz\Http\RequestMethod; use Bluz\Proxy\Request; use Zend\Diactoros\ServerRequest; use Zend\Diactoros\ServerRequestFactory; /** * Request Factory * * @package Bluz\Request * @author Anton Shevchuk */ class RequestFactory extends ServerRequestFactory { /** * {@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, RequestMethod::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 (false !== $contentType && false !== stripos($contentType, Request::TYPE_JSON)) { $data = (array) json_decode($input); } elseif ($request->getMethod() === RequestMethod::POST) { $data = $_POST; } else { parse_str($input, $data); } return $request ->withCookieParams($cookies ?: $_COOKIE) ->withQueryParams($query ?: $_GET) ->withParsedBody($body ?: $data); } } |