Symfony\Component\HttpFoundation\Request::createFromGlobals PHP Method

createFromGlobals() public static method

Creates a new request with values from PHP's super globals.
public static createFromGlobals ( ) : Request
return Request A new request
    public static function createFromGlobals()
    {
        // With the php's bug #66606, the php's built-in web server
        // stores the Content-Type and Content-Length header values in
        // HTTP_CONTENT_TYPE and HTTP_CONTENT_LENGTH fields.
        $server = $_SERVER;
        if ('cli-server' === PHP_SAPI) {
            if (array_key_exists('HTTP_CONTENT_LENGTH', $_SERVER)) {
                $server['CONTENT_LENGTH'] = $_SERVER['HTTP_CONTENT_LENGTH'];
            }
            if (array_key_exists('HTTP_CONTENT_TYPE', $_SERVER)) {
                $server['CONTENT_TYPE'] = $_SERVER['HTTP_CONTENT_TYPE'];
            }
        }

        $request = self::createRequestFromFactory($_GET, $_POST, array(), $_COOKIE, $_FILES, $server);

        if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded')
            && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), array('PUT', 'DELETE', 'PATCH'))
        ) {
            parse_str($request->getContent(), $data);
            $request->request = new ParameterBag($data);
        }

        return $request;
    }

Usage Example

Esempio n. 1
0
 /**
  * @param \Silex\Application $app
  */
 public function __construct(Silex\Application $app)
 {
     $this->app = $app;
     $this->db = $app['db'];
     $prefix = $this->app['config']->get('general/database/prefix', 'bolt_');
     // Hashstrength has a default of '10', don't allow less than '8'.
     $this->hashStrength = max($this->app['config']->get('general/hash_strength'), 8);
     $this->usertable = $prefix . 'users';
     $this->authtokentable = $prefix . 'authtoken';
     $this->users = array();
     $this->session = $app['session'];
     /*
      * Get the IP stored earlier in the request cycle. If it's missing we're on CLI so use localhost
      *
      * @see discussion in https://github.com/bolt/bolt/pull/3031
      */
     $request = Request::createFromGlobals();
     $this->hostName = $request->getHost();
     $this->remoteIP = $request->getClientIp() ?: '127.0.0.1';
     $this->userAgent = $request->server->get('HTTP_USER_AGENT');
     $this->authToken = $request->cookies->get('bolt_authtoken');
     // Set 'validsession', to see if the current session is valid.
     $this->validsession = $this->checkValidSession();
     $this->allowed = array('dashboard' => self::EDITOR, 'settings' => self::ADMIN, 'login' => self::ANONYMOUS, 'logout' => self::EDITOR, 'dbcheck' => self::ADMIN, 'dbupdate' => self::ADMIN, 'clearcache' => self::ADMIN, 'prefill' => self::DEVELOPER, 'users' => self::ADMIN, 'useredit' => self::ADMIN, 'useraction' => self::ADMIN, 'overview' => self::EDITOR, 'editcontent' => self::EDITOR, 'editcontent:own' => self::EDITOR, 'editcontent:all' => self::ADMIN, 'contentaction' => self::EDITOR, 'about' => self::EDITOR, 'extensions' => self::DEVELOPER, 'files' => self::EDITOR, 'files:config' => self::DEVELOPER, 'files:theme' => self::DEVELOPER, 'files:uploads' => self::ADMIN, 'translation' => self::DEVELOPER, 'activitylog' => self::ADMIN, 'fileedit' => self::ADMIN);
 }
All Usage Examples Of Symfony\Component\HttpFoundation\Request::createFromGlobals