1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-29 02:02:40 +01:00
phorge-arcanist/src/utils/PhutilArray.php
epriestley 9b74cb4ee6 Fully merge "libphutil/" into "arcanist/"
Summary: Ref T13395. Moves all remaining code in "libphutil/" into "arcanist/".

Test Plan: Ran various arc workflows, although this probably has some remaining rough edges.

Maniphest Tasks: T13395

Differential Revision: https://secure.phabricator.com/D20980
2020-02-12 15:17:38 -08:00

80 lines
1.6 KiB
PHP

<?php
/**
* Abstract base class for implementing objects that behave like arrays. This
* class wraps a basic array and provides trivial implementations for
* `Countable`, `ArrayAccess` and `Iterator`, so subclasses need only implement
* specializations.
*/
abstract class PhutilArray
extends Phobject
implements Countable, ArrayAccess, Iterator {
protected $data = array();
public function __construct(array $initial_value = array()) {
$this->data = $initial_value;
}
/* -( Conversion )--------------------------------------------------------- */
public function toArray() {
return iterator_to_array($this, true);
}
/* -( Countable Interface )------------------------------------------------ */
public function count() {
return count($this->data);
}
/* -( Iterator Interface )------------------------------------------------- */
public function current() {
return current($this->data);
}
public function key() {
return key($this->data);
}
public function next() {
return next($this->data);
}
public function rewind() {
reset($this->data);
}
public function valid() {
return (key($this->data) !== null);
}
/* -( ArrayAccess Interface )---------------------------------------------- */
public function offsetExists($key) {
return array_key_exists($key, $this->data);
}
public function offsetGet($key) {
return $this->data[$key];
}
public function offsetSet($key, $value) {
$this->data[$key] = $value;
}
public function offsetUnset($key) {
unset($this->data[$key]);
}
}