A super easy PHP Framework for web development! https://github.com/exacti/phacil-framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
1.9 KiB

2 years ago
<?php
/*
* Copyright © 2023 ExacTI Technology Solutions. All rights reserved.
* GPLv3 General License.
* https://exacti.com.br
*/
namespace Phacil\Framework\ArrayClass;
class CaseInsensitiveArray implements \ArrayAccess
{
private $_container = array();
/**
* @param array $initial_array
* @return void
*/
public function __construct(array $initial_array = array())
{
//$this->_container = array_map("strtolower", $initial_array);
$this->_container = array_change_key_case($initial_array);
}
/**
* Assigns a value to the specified offset
*
* @param string $offset The offset to assign the value to
* @param mixed $value The value to set
* @access public
* @abstracting ArrayAccess
*
* @return void
*/
public function offsetSet($offset, $value)
{
if (is_string($offset)) $offset = strtolower($offset);
if (is_null($offset)) {
$this->_container[] = $value;
} else {
$this->_container[$offset] = $value;
}
}
/**
* Whether or not an offset exists
*
* @param string $offset An offset to check for
* @access public
* @return bool
* @abstracting ArrayAccess
*/
public function offsetExists($offset)
{
if (is_string($offset)) $offset = strtolower($offset);
return isset($this->_container[$offset]);
}
/**
* Unsets an offset
*
* @param string $offset The offset to unset
* @access public
* @abstracting ArrayAccess
*
* @return void
*/
public function offsetUnset($offset)
{
if (is_string($offset)) $offset = strtolower($offset);
unset($this->_container[$offset]);
}
/**
* Returns the value at specified offset
*
* @param string $offset The offset to retrieve
* @access public
* @return mixed
* @abstracting ArrayAccess
*/
public function offsetGet($offset)
{
if (is_string($offset)) $offset = strtolower($offset);
return isset($this->_container[$offset])
? $this->_container[$offset]
: null;
}
}