lithium\net\http\Response::__construct PHP Method

__construct() public method

Constructor. Adds config values to the public properties when a new object is created.
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. - `'message'` _string_: Defaults to `null`. - `'status'` _mixed_: Defaults to `null`. - `'type'` _string_: Defaults to `null`. - `'cookies'` _array_: Defaults to `array()`.
return void
    public function __construct(array $config = array())
    {
        $defaults = array('message' => null, 'status' => null, 'type' => null, 'cookies' => array());
        parent::__construct($config + $defaults);
        if ($this->_config['message']) {
            $this->body = $this->_parseMessage($this->_config['message']);
        }
        if ($this->headers('Transfer-Encoding')) {
            $this->body = $this->_httpChunkedDecode($this->body);
        }
        if ($status = $this->_config['status']) {
            $this->status($status);
        }
        if ($cookies = $this->headers('Set-Cookie')) {
            $this->_parseCookies($cookies);
        }
        if ($cookies = $this->_config['cookies']) {
            $this->cookies($cookies);
        }
        if ($type = $this->_config['type']) {
            $this->type($type);
        }
        if (!($header = $this->headers('Content-Type'))) {
            return;
        }
        $header = is_array($header) ? end($header) : $header;
        preg_match('/([-\\w\\/\\.+]+)(;\\s*?charset=(.+))?/i', $header, $match);
        if (isset($match[1])) {
            $this->type(trim($match[1]));
        }
        if (isset($match[3])) {
            $this->encoding = strtoupper(trim($match[3]));
        }
    }

Usage Example

 public function __construct(array $config = array())
 {
     $defaults = array('buffer' => 8192, 'location' => null, 'status' => 0, 'request' => null, 'decode' => false);
     parent::__construct($config + $defaults);
 }
All Usage Examples Of lithium\net\http\Response::__construct