class FieldChain in Corresponding Entity References 7.3
@class A doubly linked list of FieldInstance objects.
Hierarchy
- class \FieldChain implements \SeekableIterator
Expanded class hierarchy of FieldChain
File
- field_object/
includes/ FieldChain.inc, line 12 - Contains the FieldChain class.
View source
class FieldChain implements SeekableIterator {
protected $chain = array();
protected $index = 0;
/**
* Magic post-unserialization callback. Provides every field in the chain
* with a reference to its parent (if any) and child (if any), effectively
* turning the chain into a doubly linked list.
*/
public function __wakeup() {
foreach ($this->chain as $field) {
if (isset($parent)) {
$field
->parent($parent)
->child($field);
}
$parent = $field;
}
}
/**
* Represents this chain as a machine-readable string, separating the fields
* with a T_PAAMAYIM_NEKUDOTAYIM (or, as we call it on planet Earth, a
* double colon).
*/
public function __toString() {
$key = array();
foreach ($this->chain as $field) {
$key[] = $field
->__toString();
}
return implode('::', $key);
}
/**
* Prepends a field instance to this chain. If $completed is passed, we'll
* try to find the parents of the instance and recurse upwards, building
* a tree of "routes" to the instance.
*/
public function addField(FieldInstance $field, array &$completed = NULL) {
array_unshift($this->chain, $field);
$this
->__wakeup();
if (isset($completed)) {
$parents = $field
->getParents();
if ($parents) {
foreach ($parents as $parent) {
$branch = clone $this;
$branch
->addField($parent, $completed);
}
}
else {
$completed[] = $this;
}
}
}
/**
* Returns the last field in the chain.
*/
public function end() {
return end($this->chain);
}
/**
* Implements SeekableIterator::seek().
*/
public function seek($position) {
if ($position >= 0 && $position < sizeof($this->chain)) {
$this->index = $position;
}
else {
throw new OutOfBoundsException(t('Cannot seek to invalid position %position.', array(
'%position' => $position,
)));
}
}
/**
* Implements Iterator::current().
*/
public function current() {
return $this->chain[$this->index];
}
/**
* Implements Iterator::key().
*/
public function key() {
return $this
->current()
->__toString();
}
/**
* Implements Iterator::next().
*/
public function next() {
$this->index++;
}
/**
* Implements Iterator::rewind().
*/
public function rewind() {
$this->index = 0;
}
/**
* Implements Iterator::valid().
*/
public function valid() {
return $this->index < sizeof($this->chain);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FieldChain:: |
protected | property | ||
FieldChain:: |
protected | property | ||
FieldChain:: |
public | function | Prepends a field instance to this chain. If $completed is passed, we'll try to find the parents of the instance and recurse upwards, building a tree of "routes" to the instance. | |
FieldChain:: |
public | function | Implements Iterator::current(). | |
FieldChain:: |
public | function | Returns the last field in the chain. | |
FieldChain:: |
public | function | Implements Iterator::key(). | |
FieldChain:: |
public | function | Implements Iterator::next(). | |
FieldChain:: |
public | function | Implements Iterator::rewind(). | |
FieldChain:: |
public | function | Implements SeekableIterator::seek(). | |
FieldChain:: |
public | function | Implements Iterator::valid(). | |
FieldChain:: |
public | function | Represents this chain as a machine-readable string, separating the fields with a T_PAAMAYIM_NEKUDOTAYIM (or, as we call it on planet Earth, a double colon). | |
FieldChain:: |
public | function | Magic post-unserialization callback. Provides every field in the chain with a reference to its parent (if any) and child (if any), effectively turning the chain into a doubly linked list. |