public static function createFromGlobals()
    {
        $server = $_SERVER;

        $uriParts = parse_url($server['REQUEST_URI']);

        if(isset($server['HTTP_HOST']))
        {
            list($host, $port) = explode(':', $server['HTTP_HOST']);
            $uriParts['host'] = $host;
            $uriParts['port'] = $port;
        }
        else
        {
            $uriParts['host'] = $server['SERVER_NAME'];
            $uriParts['port'] = $server['SERVER_PORT'];
        }

        $uriParts['scheme'] = isset($server['REQUEST_SCHEME']) ? $server['REQUEST_SCHEME'] : ( isset($server['HTTPS']) && $server['HTTPS'] == 'on' ? 'https' : 'http' );

        $headers = array();

        if(function_exists('getallheaders'))
        {
            // a correct case already
            $apacheHeaders = getallheaders();

            foreach($apacheHeaders as $header => $value)
                $headers[$header] = array_map('trim', explode(',', $value));
        }
        else
        {

            // normalize the header key
            foreach($server as $key => $value)
            {
                if(substr($key, 0, 5) != 'HTTP_')
                    continue;

                $name = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));

                $headers[$name] = array_map('trim', explode(',', $value));
            }
        }

        $request = new static(
            $server['REQUEST_METHOD'],
            new Uri($uriParts),
            $headers,
            Stream::createFromContents(file_get_contents('php://input')),
            $server,
            $_COOKIE,
            UploadedFile::createFromGlobals($_FILES)
        );

        if($server['REQUEST_METHOD'] == 'POST' && in_array($request->getMediaType(), array('application/x-www-form-urlencoded', 'multipart/form-data')))
            $request->setParsedBody($_POST);

        return $request;
    }
public static function createFromGlobals()
    {
        $server = $_SERVER;

        $uriParts = parse_url($server['REQUEST_URI']);

        if(isset($server['HTTP_HOST']))
        {
            list($host, $port) = explode(':', $server['HTTP_HOST']);
            $uriParts['host'] = $host;
            $uriParts['port'] = $port;
        }
        else
        {
            $uriParts['host'] = $server['SERVER_NAME'];
            $uriParts['port'] = $server['SERVER_PORT'];
        }

        $uriParts['scheme'] = isset($server['REQUEST_SCHEME']) ? $server['REQUEST_SCHEME'] : ( isset($server['HTTPS']) && $server['HTTPS'] == 'on' ? 'https' : 'http' );

        $headers = array();

        if(function_exists('getallheaders'))
        {
            // a correct case already
            $apacheHeaders = getallheaders();

            foreach($apacheHeaders as $header => $value)
                $headers[$header] = array_map('trim', explode(',', $value));
        }
        else
        {

            // normalize the header key
            foreach($server as $key => $value)
            {
                if(substr($key, 0, 5) != 'HTTP_')
                    continue;

                $name = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));

                $headers[$name] = array_map('trim', explode(',', $value));
            }
        }

        $request = new static(
            $server['REQUEST_METHOD'],
            new Uri($uriParts),
            $headers,
            Stream::createFromContents(file_get_contents('php://input')),
            $server,
            $_COOKIE,
            UploadedFile::createFromGlobals($_FILES)
        );

        if($server['REQUEST_METHOD'] == 'POST' && in_array($request->getMediaType(), array('application/x-www-form-urlencoded', 'multipart/form-data')))
            $request->setParsedBody($_POST);

        return $request;
    }
public static function createFromGlobals ( ) { $ server = $ _SERVER ; $ uriParts = parse_url ( $ server [ 'REQUEST_URI' ] ) ; if ( isset ( $ server [ 'HTTP_HOST' ] ) ) { list ( $ host , $ port ) = explode ( ':' , $ server [ 'HTTP_HOST' ] ) ; $ uriParts [ 'host' ] = $ host ; $ uriParts [ 'port' ] = $ port ; } else { $ uriParts [ 'host' ] = $ server [ 'SERVER_NAME' ] ; $ uriParts [ 'port' ] = $ server [ 'SERVER_PORT' ] ; } $ uriParts [ 'scheme' ] = isset ( $ server [ 'REQUEST_SCHEME' ] ) ? $ server [ 'REQUEST_SCHEME' ] : ( isset ( $ server [ 'HTTPS' ] ) && $ server [ 'HTTPS' ] == 'on' ? 'https' : 'http' ) ; $ headers = array ( ) ; if ( function_exists ( 'getallheaders' ) ) { // a correct case already $ apacheHeaders = getallheaders ( ) ; foreach ( $ apacheHeaders as $ header => $ value ) $ headers [ $ header ] = array_map ( 'trim' , explode ( ',' , $ value ) ) ; } else { // normalize the header key foreach ( $ server as $ key => $ value ) { if ( substr ( $ key , 0 , 5 ) != 'HTTP_' ) continue ; $ name = str_replace ( ' ' , '-' , ucwords ( str_replace ( '_' , ' ' , strtolower ( substr ( $ key , 5 ) ) ) ) ) ; $ headers [ $ name ] = array_map ( 'trim' , explode ( ',' , $ value ) ) ; } } $ request = new static ( $ server [ 'REQUEST_METHOD' ] , new Uri ( $ uriParts ) , $ headers , Stream :: createFromContents ( file_get_contents ( 'php://input' ) ) , $ server , $ _COOKIE , UploadedFile :: createFromGlobals ( $ _FILES ) ) ; if ( $ server [ 'REQUEST_METHOD' ] == 'POST' && in_array ( $ request -> getMediaType ( ) , array ( 'application/x-www-form-urlencoded' , 'multipart/form-data' ) ) ) $ request -> setParsedBody ( $ _POST ) ; return $ request ; }
Instantiate request from php _SERVER variable
@return static
Instantiate request from php _SERVER variable