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.
PhpCollections/src/ArrayClasses/TInternalArray.php

45 lines
1008 B
PHP

<?php
namespace jrosset\ArrayClasses;
use OutOfRangeException;
trait TInternalArray {
/**
* @inheritDoc
*/
public function set ($cellName, $cellValue): self {
$this->array[$cellName] = $cellValue;
return $this;
}
/**
* @inheritDoc
*/
public function push ($cellValue): self {
return $this->set($this->count(), $cellValue);
}
/**
* @inheritDoc
*/
public function del ($cellName, ?bool $throwsForNonExistentElement = null): self {
if ($throwsForNonExistentElement ?? $this->throwsForNonExistentElement() && !$this->has($cellName)) {
throw new OutOfRangeException();
}
unset($this->array[$cellName]);
return $this;
}
/**
* @inheritDoc
*/
public function offsetSet ($offset, $value): void {
$this->set($offset, $value);
}
/**
* @inheritDoc
*/
public function offsetUnset ($offset): void {
$this->del($offset);
}
}