interpreter = $interpreter;
$this->data = $data;
}
/**
* Initialize the attributes array
*/
private function init() {
if ( $this->attributes === null ) {
$func = $this->interpreter;
$this->attributes = $func( $this->data );
// @phan-suppress-next-line PhanTypeMismatchProperty
$this->interpreter = null;
$this->data = null;
}
}
public function offsetExists( $offset ) {
if ( $this->attributes === null ) {
$this->init();
}
return isset( $this->attributes[$offset] );
}
public function &offsetGet( $offset ) {
if ( $this->attributes === null ) {
$this->init();
}
return $this->attributes[$offset];
}
public function offsetSet( $offset, $value ) {
if ( $this->attributes === null ) {
$this->init();
}
$this->attributes[$offset] = $value;
if ( $this->attrObjects !== null ) {
$this->attrObjects[$offset] = new Attribute( $offset, null, null, $offset, $value );
}
}
public function offsetUnset( $offset ) {
if ( $this->attributes === null ) {
$this->init();
}
unset( $this->attributes[$offset] );
unset( $this->attrObjects[$offset] );
}
public function getValues() {
if ( $this->attributes === null ) {
$this->init();
}
return $this->attributes;
}
public function getObjects() {
if ( $this->attrObjects === null ) {
if ( $this->attributes === null ) {
$this->init();
}
$result = [];
foreach ( $this->attributes as $name => $value ) {
$result[$name] = new Attribute( $name, null, null, $name, $value );
}
$this->attrObjects = $result;
}
return $this->attrObjects;
}
public function count() {
if ( $this->attributes === null ) {
return count( $this->data );
}
return count( $this->attributes );
}
public function getIterator() {
if ( $this->attributes === null ) {
$this->init();
}
return new \ArrayIterator( $this->attributes );
}
public function merge( Attributes $other ) {
if ( $this->attributes === null ) {
$this->init();
}
foreach ( $other as $name => $value ) {
if ( !isset( $this->attributes[$name] ) ) {
$this->attributes[$name] = $value;
}
}
}
}