public function EasyRdf_Collection::offsetUnset in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Collection.php \EasyRdf_Collection::offsetUnset()
Array Access: delete an item at a specific postion using array syntax
Example: unset($seq[2]);
File
- vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ Collection.php, line 293
Class
- EasyRdf_Collection
- Sub-class of EasyRdf_Resource that represents an RDF collection (rdf:List)
Code
public function offsetUnset($offset) {
if (is_int($offset) and $offset > 0) {
list($node, $position) = $this
->getCollectionNode($offset);
}
else {
throw new InvalidArgumentException("Collection offset must be a positive integer");
}
// Does the item exist?
if ($node and $position === $offset) {
$nil = $this->graph
->resource('rdf:nil');
if ($position === 1) {
$rest = $node
->get('rdf:rest');
if ($rest and $rest !== $nil) {
// Move second value, so we can keep the head of list
$node
->set('rdf:first', $rest
->get('rdf:first'));
$node
->set('rdf:rest', $rest
->get('rdf:rest'));
$rest
->delete('rdf:first');
$rest
->delete('rdf:rest');
}
else {
// Just remove the value
$node
->delete('rdf:first');
$node
->delete('rdf:rest');
}
}
else {
// Remove the value and re-link the list
$node
->delete('rdf:first');
$rest = $node
->get('rdf:rest');
$previous = $node
->get('^rdf:rest');
if (is_null($rest)) {
$rest = $nil;
}
if ($previous) {
$previous
->set('rdf:rest', $rest);
}
}
}
}