Session::__construct( string|WpOrgRequestsStringable|null $url = null, array $headers = array(), array $data = array(), array $options = array() )

In this article

Create a new session

Parameters

$urlstring|WpOrgRequestsStringable|nulloptional
Base URL for requests

Default:null

$headersarrayoptional
Default headers for requests

Default:array()

$dataarrayoptional
Default data for requests

Default:array()

$optionsarrayoptional
Default options for requests

Default:array()

Source

public function __construct($url = null, $headers = [], $data = [], $options = []) {
	if ($url !== null && InputValidator::is_string_or_stringable($url) === false) {
		throw InvalidArgument::create(1, '$url', 'string|Stringable|null', gettype($url));
	}

	if (is_array($headers) === false) {
		throw InvalidArgument::create(2, '$headers', 'array', gettype($headers));
	}

	if (is_array($data) === false) {
		throw InvalidArgument::create(3, '$data', 'array', gettype($data));
	}

	if (is_array($options) === false) {
		throw InvalidArgument::create(4, '$options', 'array', gettype($options));
	}

	$this->url     = $url;
	$this->headers = $headers;
	$this->data    = $data;
	$this->options = $options;

	if (empty($this->options['cookies'])) {
		$this->options['cookies'] = new Jar();
	}
}

User Contributed Notes

You must log in before being able to contribute a note or feedback.