lithium\net\http\Response::__construct()

public method

Constructor. Adds config values to the public properties when a new object is created.

Parameters

  • array $config

    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().

Returns

void

Source

	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]));
		}
	}