You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace jrosset\ArrayClasses;
|
|
|
|
/**
|
|
* An immutable array with insensitive case cell name
|
|
*/
|
|
class ImmutableInsensitiveCaseArrayClass implements IImmutableArrayClass {
|
|
use TImmutableInternalArray {
|
|
__construct as private __construct__TImmutableInternalArray;
|
|
has as private has__TImmutableInternalArray;
|
|
get as private get__TImmutableInternalArray;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function __construct ($initial = null, bool $throwsForNonExistentElement = true) {
|
|
$this->__construct__TImmutableInternalArray($initial, $throwsForNonExistentElement);
|
|
|
|
$arrayNew = [];
|
|
foreach ($this->array as $key => $value) {
|
|
$arrayNew[mb_strtolower($key)] = $value;
|
|
}
|
|
$this->array = $arrayNew;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function has ($cellName): bool {
|
|
return $this->has__TImmutableInternalArray(mb_strtolower($cellName));
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function get ($cellName, ?bool $throwsForNonExistentElement = null) {
|
|
return $this->get__TImmutableInternalArray(mb_strtolower($cellName), $throwsForNonExistentElement);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function toMutable (): IArrayClass {
|
|
return new InsensitiveCaseArrayClass($this->array, $this->throwsForNonExistentElement());
|
|
}
|
|
} |