Edit File by line
/home/barbar84/public_h.../wp-inclu.../Requests
File: Session.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Session handler for persistent requests and default parameters
[2] Fix | Delete
*
[3] Fix | Delete
* @package Requests
[4] Fix | Delete
* @subpackage Session Handler
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Session handler for persistent requests and default parameters
[9] Fix | Delete
*
[10] Fix | Delete
* Allows various options to be set as default values, and merges both the
[11] Fix | Delete
* options and URL properties together. A base URL can be set for all requests,
[12] Fix | Delete
* with all subrequests resolved from this. Base options can be set (including
[13] Fix | Delete
* a shared cookie jar), then overridden for individual requests.
[14] Fix | Delete
*
[15] Fix | Delete
* @package Requests
[16] Fix | Delete
* @subpackage Session Handler
[17] Fix | Delete
*/
[18] Fix | Delete
class Requests_Session {
[19] Fix | Delete
/**
[20] Fix | Delete
* Base URL for requests
[21] Fix | Delete
*
[22] Fix | Delete
* URLs will be made absolute using this as the base
[23] Fix | Delete
* @var string|null
[24] Fix | Delete
*/
[25] Fix | Delete
public $url = null;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Base headers for requests
[29] Fix | Delete
* @var array
[30] Fix | Delete
*/
[31] Fix | Delete
public $headers = array();
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Base data for requests
[35] Fix | Delete
*
[36] Fix | Delete
* If both the base data and the per-request data are arrays, the data will
[37] Fix | Delete
* be merged before sending the request.
[38] Fix | Delete
*
[39] Fix | Delete
* @var array
[40] Fix | Delete
*/
[41] Fix | Delete
public $data = array();
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Base options for requests
[45] Fix | Delete
*
[46] Fix | Delete
* The base options are merged with the per-request data for each request.
[47] Fix | Delete
* The only default option is a shared cookie jar between requests.
[48] Fix | Delete
*
[49] Fix | Delete
* Values here can also be set directly via properties on the Session
[50] Fix | Delete
* object, e.g. `$session->useragent = 'X';`
[51] Fix | Delete
*
[52] Fix | Delete
* @var array
[53] Fix | Delete
*/
[54] Fix | Delete
public $options = array();
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Create a new session
[58] Fix | Delete
*
[59] Fix | Delete
* @param string|null $url Base URL for requests
[60] Fix | Delete
* @param array $headers Default headers for requests
[61] Fix | Delete
* @param array $data Default data for requests
[62] Fix | Delete
* @param array $options Default options for requests
[63] Fix | Delete
*/
[64] Fix | Delete
public function __construct($url = null, $headers = array(), $data = array(), $options = array()) {
[65] Fix | Delete
$this->url = $url;
[66] Fix | Delete
$this->headers = $headers;
[67] Fix | Delete
$this->data = $data;
[68] Fix | Delete
$this->options = $options;
[69] Fix | Delete
[70] Fix | Delete
if (empty($this->options['cookies'])) {
[71] Fix | Delete
$this->options['cookies'] = new Requests_Cookie_Jar();
[72] Fix | Delete
}
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Get a property's value
[77] Fix | Delete
*
[78] Fix | Delete
* @param string $key Property key
[79] Fix | Delete
* @return mixed|null Property value, null if none found
[80] Fix | Delete
*/
[81] Fix | Delete
public function __get($key) {
[82] Fix | Delete
if (isset($this->options[$key])) {
[83] Fix | Delete
return $this->options[$key];
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
return null;
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
/**
[90] Fix | Delete
* Set a property's value
[91] Fix | Delete
*
[92] Fix | Delete
* @param string $key Property key
[93] Fix | Delete
* @param mixed $value Property value
[94] Fix | Delete
*/
[95] Fix | Delete
public function __set($key, $value) {
[96] Fix | Delete
$this->options[$key] = $value;
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Remove a property's value
[101] Fix | Delete
*
[102] Fix | Delete
* @param string $key Property key
[103] Fix | Delete
*/
[104] Fix | Delete
public function __isset($key) {
[105] Fix | Delete
return isset($this->options[$key]);
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
/**
[109] Fix | Delete
* Remove a property's value
[110] Fix | Delete
*
[111] Fix | Delete
* @param string $key Property key
[112] Fix | Delete
*/
[113] Fix | Delete
public function __unset($key) {
[114] Fix | Delete
if (isset($this->options[$key])) {
[115] Fix | Delete
unset($this->options[$key]);
[116] Fix | Delete
}
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
/**#@+
[120] Fix | Delete
* @see request()
[121] Fix | Delete
* @param string $url
[122] Fix | Delete
* @param array $headers
[123] Fix | Delete
* @param array $options
[124] Fix | Delete
* @return Requests_Response
[125] Fix | Delete
*/
[126] Fix | Delete
/**
[127] Fix | Delete
* Send a GET request
[128] Fix | Delete
*/
[129] Fix | Delete
public function get($url, $headers = array(), $options = array()) {
[130] Fix | Delete
return $this->request($url, $headers, null, Requests::GET, $options);
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
/**
[134] Fix | Delete
* Send a HEAD request
[135] Fix | Delete
*/
[136] Fix | Delete
public function head($url, $headers = array(), $options = array()) {
[137] Fix | Delete
return $this->request($url, $headers, null, Requests::HEAD, $options);
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
* Send a DELETE request
[142] Fix | Delete
*/
[143] Fix | Delete
public function delete($url, $headers = array(), $options = array()) {
[144] Fix | Delete
return $this->request($url, $headers, null, Requests::DELETE, $options);
[145] Fix | Delete
}
[146] Fix | Delete
/**#@-*/
[147] Fix | Delete
[148] Fix | Delete
/**#@+
[149] Fix | Delete
* @see request()
[150] Fix | Delete
* @param string $url
[151] Fix | Delete
* @param array $headers
[152] Fix | Delete
* @param array $data
[153] Fix | Delete
* @param array $options
[154] Fix | Delete
* @return Requests_Response
[155] Fix | Delete
*/
[156] Fix | Delete
/**
[157] Fix | Delete
* Send a POST request
[158] Fix | Delete
*/
[159] Fix | Delete
public function post($url, $headers = array(), $data = array(), $options = array()) {
[160] Fix | Delete
return $this->request($url, $headers, $data, Requests::POST, $options);
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
/**
[164] Fix | Delete
* Send a PUT request
[165] Fix | Delete
*/
[166] Fix | Delete
public function put($url, $headers = array(), $data = array(), $options = array()) {
[167] Fix | Delete
return $this->request($url, $headers, $data, Requests::PUT, $options);
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
/**
[171] Fix | Delete
* Send a PATCH request
[172] Fix | Delete
*
[173] Fix | Delete
* Note: Unlike {@see post} and {@see put}, `$headers` is required, as the
[174] Fix | Delete
* specification recommends that should send an ETag
[175] Fix | Delete
*
[176] Fix | Delete
* @link https://tools.ietf.org/html/rfc5789
[177] Fix | Delete
*/
[178] Fix | Delete
public function patch($url, $headers, $data = array(), $options = array()) {
[179] Fix | Delete
return $this->request($url, $headers, $data, Requests::PATCH, $options);
[180] Fix | Delete
}
[181] Fix | Delete
/**#@-*/
[182] Fix | Delete
[183] Fix | Delete
/**
[184] Fix | Delete
* Main interface for HTTP requests
[185] Fix | Delete
*
[186] Fix | Delete
* This method initiates a request and sends it via a transport before
[187] Fix | Delete
* parsing.
[188] Fix | Delete
*
[189] Fix | Delete
* @see Requests::request()
[190] Fix | Delete
*
[191] Fix | Delete
* @throws Requests_Exception On invalid URLs (`nonhttp`)
[192] Fix | Delete
*
[193] Fix | Delete
* @param string $url URL to request
[194] Fix | Delete
* @param array $headers Extra headers to send with the request
[195] Fix | Delete
* @param array|null $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
[196] Fix | Delete
* @param string $type HTTP request type (use Requests constants)
[197] Fix | Delete
* @param array $options Options for the request (see {@see Requests::request})
[198] Fix | Delete
* @return Requests_Response
[199] Fix | Delete
*/
[200] Fix | Delete
public function request($url, $headers = array(), $data = array(), $type = Requests::GET, $options = array()) {
[201] Fix | Delete
$request = $this->merge_request(compact('url', 'headers', 'data', 'options'));
[202] Fix | Delete
[203] Fix | Delete
return Requests::request($request['url'], $request['headers'], $request['data'], $type, $request['options']);
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
/**
[207] Fix | Delete
* Send multiple HTTP requests simultaneously
[208] Fix | Delete
*
[209] Fix | Delete
* @see Requests::request_multiple()
[210] Fix | Delete
*
[211] Fix | Delete
* @param array $requests Requests data (see {@see Requests::request_multiple})
[212] Fix | Delete
* @param array $options Global and default options (see {@see Requests::request})
[213] Fix | Delete
* @return array Responses (either Requests_Response or a Requests_Exception object)
[214] Fix | Delete
*/
[215] Fix | Delete
public function request_multiple($requests, $options = array()) {
[216] Fix | Delete
foreach ($requests as $key => $request) {
[217] Fix | Delete
$requests[$key] = $this->merge_request($request, false);
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
$options = array_merge($this->options, $options);
[221] Fix | Delete
[222] Fix | Delete
// Disallow forcing the type, as that's a per request setting
[223] Fix | Delete
unset($options['type']);
[224] Fix | Delete
[225] Fix | Delete
return Requests::request_multiple($requests, $options);
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
public function __wakeup() {
[229] Fix | Delete
throw new \LogicException( __CLASS__ . ' should never be unserialized' );
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
/**
[233] Fix | Delete
* Merge a request's data with the default data
[234] Fix | Delete
*
[235] Fix | Delete
* @param array $request Request data (same form as {@see request_multiple})
[236] Fix | Delete
* @param boolean $merge_options Should we merge options as well?
[237] Fix | Delete
* @return array Request data
[238] Fix | Delete
*/
[239] Fix | Delete
protected function merge_request($request, $merge_options = true) {
[240] Fix | Delete
if ($this->url !== null) {
[241] Fix | Delete
$request['url'] = Requests_IRI::absolutize($this->url, $request['url']);
[242] Fix | Delete
$request['url'] = $request['url']->uri;
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
if (empty($request['headers'])) {
[246] Fix | Delete
$request['headers'] = array();
[247] Fix | Delete
}
[248] Fix | Delete
$request['headers'] = array_merge($this->headers, $request['headers']);
[249] Fix | Delete
[250] Fix | Delete
if (empty($request['data'])) {
[251] Fix | Delete
if (is_array($this->data)) {
[252] Fix | Delete
$request['data'] = $this->data;
[253] Fix | Delete
}
[254] Fix | Delete
}
[255] Fix | Delete
elseif (is_array($request['data']) && is_array($this->data)) {
[256] Fix | Delete
$request['data'] = array_merge($this->data, $request['data']);
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
if ($merge_options !== false) {
[260] Fix | Delete
$request['options'] = array_merge($this->options, $request['options']);
[261] Fix | Delete
[262] Fix | Delete
// Disallow forcing the type, as that's a per request setting
[263] Fix | Delete
unset($request['options']['type']);
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
return $request;
[267] Fix | Delete
}
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function