lithium\action\Request::__construct PHP Method

__construct() public method

Normalizes casing of request headers.
See also: lithium\net\http\Request::__construct()
See also: lithium\net\http\Message::__construct()
See also: lithium\net\Message::__construct()
public __construct ( array $config = [] ) : void
$config array The available configuration options are the following. Further options are inherited from the parent classes. - `'base'` _string_: Defaults to `null`. - `'url'` _string_: Defaults to `null`. - `'data'` _array_: Additional data to use when initializing the request. Defaults to `array()`. - `'stream'` _resource_: Stream to read from in order to get the message body when method is POST, PUT or PATCH and data is empty. When not provided `php://input` will be used for reading. - `'env'` _array_: Defaults to `array()`. - `'globals'` _boolean_: Use global variables for populating the request's environment and data; defaults to `true`.
return void
    public function __construct(array $config = array())
    {
        $defaults = array('base' => null, 'url' => null, 'env' => array(), 'data' => array(), 'stream' => null, 'globals' => true, 'query' => array(), 'headers' => array());
        $config += $defaults;
        if ($config['globals']) {
            if (isset($_SERVER)) {
                $config['env'] += $_SERVER;
            }
            if (isset($_ENV)) {
                $config['env'] += $_ENV;
            }
            if (isset($_GET)) {
                $config['query'] += $_GET;
            }
            if (isset($_POST)) {
                $config['data'] += $_POST;
            }
        }
        $this->_env = $config['env'];
        if (!isset($config['host'])) {
            $config['host'] = $this->env('HTTP_HOST');
        }
        if (!isset($config['protocol'])) {
            $config['protocol'] = $this->env('SERVER_PROTOCOL');
        }
        if ($config['protocol'] && strpos($config['protocol'], '/')) {
            list($scheme, $version) = explode('/', $config['protocol']);
            if (!isset($config['scheme'])) {
                $config['scheme'] = strtolower($scheme) . ($this->env('HTTPS') ? 's' : '');
            }
            if (!isset($config['version'])) {
                $config['version'] = $version;
            }
        }
        $this->_base = $this->_base($config['base']);
        $this->url = $this->_url($config['url']);
        $config['headers'] += array('Content-Type' => $this->env('CONTENT_TYPE'), 'Content-Length' => $this->env('CONTENT_LENGTH'));
        foreach ($this->_env as $name => $value) {
            if ($name[0] === 'H' && strpos($name, 'HTTP_') === 0) {
                $name = str_replace('_', ' ', substr($name, 5));
                $name = str_replace(' ', '-', ucwords(strtolower($name)));
                $config['headers'] += array($name => $value);
            }
        }
        parent::__construct($config);
    }