mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-07 19:31:54 +01:00
f221b3eb54
While some of the changes in the `1.8.0` release have already been copied to WordPress Core in earlier releases (see [38727], [46258], [47902] and [49382]), this release contains additional improvements, including: - A significant performance fix when using cURL. - Improved compliance with RFC2616. The library has also been moved under the WordPress project’s GitHub organization and can now be found at https://github.com/WordPress/Requests. Props jrf, dd32, rmccue, justinahinon, netweb, schlessera, TimothyBJacobs, soulseekah, ozh, skithund, carlalexander, travisnorthcutt, desrosj. Fixes #53101. Built from https://develop.svn.wordpress.org/trunk@50842 git-svn-id: http://core.svn.wordpress.org/trunk@50451 1a063a9b-81f0-0310-95a4-ce76da25c4cd
104 lines
2.0 KiB
PHP
104 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* Case-insensitive dictionary, suitable for HTTP headers
|
|
*
|
|
* @package Requests
|
|
* @subpackage Utilities
|
|
*/
|
|
|
|
/**
|
|
* Case-insensitive dictionary, suitable for HTTP headers
|
|
*
|
|
* @package Requests
|
|
* @subpackage Utilities
|
|
*/
|
|
class Requests_Utility_CaseInsensitiveDictionary implements ArrayAccess, IteratorAggregate {
|
|
/**
|
|
* Actual item data
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $data = array();
|
|
|
|
/**
|
|
* Creates a case insensitive dictionary.
|
|
*
|
|
* @param array $data Dictionary/map to convert to case-insensitive
|
|
*/
|
|
public function __construct(array $data = array()) {
|
|
foreach ($data as $key => $value) {
|
|
$this->offsetSet($key, $value);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if the given item exists
|
|
*
|
|
* @param string $key Item key
|
|
* @return boolean Does the item exist?
|
|
*/
|
|
public function offsetExists($key) {
|
|
$key = strtolower($key);
|
|
return isset($this->data[$key]);
|
|
}
|
|
|
|
/**
|
|
* Get the value for the item
|
|
*
|
|
* @param string $key Item key
|
|
* @return string|null Item value (null if offsetExists is false)
|
|
*/
|
|
public function offsetGet($key) {
|
|
$key = strtolower($key);
|
|
if (!isset($this->data[$key])) {
|
|
return null;
|
|
}
|
|
|
|
return $this->data[$key];
|
|
}
|
|
|
|
/**
|
|
* Set the given item
|
|
*
|
|
* @throws Requests_Exception On attempting to use dictionary as list (`invalidset`)
|
|
*
|
|
* @param string $key Item name
|
|
* @param string $value Item value
|
|
*/
|
|
public function offsetSet($key, $value) {
|
|
if ($key === null) {
|
|
throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset');
|
|
}
|
|
|
|
$key = strtolower($key);
|
|
$this->data[$key] = $value;
|
|
}
|
|
|
|
/**
|
|
* Unset the given header
|
|
*
|
|
* @param string $key
|
|
*/
|
|
public function offsetUnset($key) {
|
|
unset($this->data[strtolower($key)]);
|
|
}
|
|
|
|
/**
|
|
* Get an iterator for the data
|
|
*
|
|
* @return ArrayIterator
|
|
*/
|
|
public function getIterator() {
|
|
return new ArrayIterator($this->data);
|
|
}
|
|
|
|
/**
|
|
* Get the headers as an array
|
|
*
|
|
* @return array Header data
|
|
*/
|
|
public function getAll() {
|
|
return $this->data;
|
|
}
|
|
}
|