Fix #254: CaseInsensitiveArray not found.

This commit is contained in:
Zach Borboa
2015-10-20 21:54:53 -07:00
parent d49186ae30
commit d69cded020
8 changed files with 92 additions and 89 deletions
+73
View File
@@ -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);
}
}