mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-25 08:19:04 +00:00
Fix #254: CaseInsensitiveArray not found.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Curl;
|
||||
|
||||
class CaseInsensitiveArray implements \ArrayAccess, \Countable, \Iterator
|
||||
{
|
||||
private $container = array();
|
||||
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
if ($offset === null) {
|
||||
$this->container[] = $value;
|
||||
} else {
|
||||
$index = array_search(strtolower($offset), array_keys(array_change_key_case($this->container, CASE_LOWER)));
|
||||
if (!($index === false)) {
|
||||
$keys = array_keys($this->container);
|
||||
unset($this->container[$keys[$index]]);
|
||||
}
|
||||
$this->container[$offset] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return array_key_exists(strtolower($offset), array_change_key_case($this->container, CASE_LOWER));
|
||||
}
|
||||
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->container[$offset]);
|
||||
}
|
||||
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
$index = array_search(strtolower($offset), array_keys(array_change_key_case($this->container, CASE_LOWER)));
|
||||
if ($index === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$values = array_values($this->container);
|
||||
return $values[$index];
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return count($this->container);
|
||||
}
|
||||
|
||||
public function current()
|
||||
{
|
||||
return current($this->container);
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
return next($this->container);
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return key($this->container);
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return !($this->current() === false);
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
reset($this->container);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user