class EasyRdf_Container in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/easyrdf/easyrdf/lib/EasyRdf/Container.php \EasyRdf_Container
Sub-class of EasyRdf_Resource that represents an RDF container (rdf:Alt, rdf:Bag and rdf:Seq)
This class can be used to iterate through a list of items.
@package EasyRdf @link http://www.w3.org/TR/xmlschema-2/#date @copyright Copyright (c) 2013 Nicholas J Humfrey @license http://www.opensource.org/licenses/bsd-license.php
Hierarchy
- class \EasyRdf_Resource
- class \EasyRdf_Container implements \ArrayAccess, \Countable, \SeekableIterator
Expanded class hierarchy of EasyRdf_Container
1 string reference to 'EasyRdf_Container'
- TypeMapper.php in vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ TypeMapper.php
File
- vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ Container.php, line 49
View source
class EasyRdf_Container extends EasyRdf_Resource implements ArrayAccess, Countable, SeekableIterator {
private $position;
/** Create a new container - do not use this directly
*
* @ignore
*/
public function __construct($uri, $graph) {
$this->position = 1;
parent::__construct($uri, $graph);
}
/** Seek to a specific position in the container
*
* The first item is postion 1
*
* @param integer $position The position in the container to seek to
* @throws OutOfBoundsException
*/
public function seek($position) {
if (is_int($position) and $position > 0) {
if ($this
->hasProperty('rdf:_' . $position)) {
$this->position = $position;
}
else {
throw new OutOfBoundsException("Unable to seek to position {$position} in the container");
}
}
else {
throw new InvalidArgumentException("Container position must be a positive integer");
}
}
/** Rewind the iterator back to the start of the container (item 1)
*
*/
public function rewind() {
$this->position = 1;
}
/** Return the current item in the container
*
* @return mixed The current item
*/
public function current() {
return $this
->get('rdf:_' . $this->position);
}
/** Return the key / current position in the container
*
* @return int The current position
*/
public function key() {
return $this->position;
}
/** Move forward to next item in the container
*
*/
public function next() {
$this->position++;
}
/** Checks if current position is valid
*
* @return bool True if the current position is valid
*/
public function valid() {
return $this
->hasProperty('rdf:_' . $this->position);
}
/** Counts the number of items in the container
*
* Note that this is an slow method - it is more efficient to use
* the iterator interface, if you can.
*
* @return integer The number of items in the container
*/
public function count() {
$pos = 1;
while ($this
->hasProperty('rdf:_' . $pos)) {
$pos++;
}
return $pos - 1;
}
/** Append an item to the end of the container
*
* @param mixed $value The value to append
* @return integer The number of values appended (1 or 0)
*/
public function append($value) {
// Find the end of the list
$pos = 1;
while ($this
->hasProperty('rdf:_' . $pos)) {
$pos++;
}
// Add the item
return $this
->add('rdf:_' . $pos, $value);
}
/** Array Access: check if a position exists in container using array syntax
*
* Example: isset($seq[2])
*/
public function offsetExists($offset) {
if (is_int($offset) and $offset > 0) {
return $this
->hasProperty('rdf:_' . $offset);
}
else {
throw new InvalidArgumentException("Container position must be a positive integer");
}
}
/** Array Access: get an item at a specified position in container using array syntax
*
* Example: $item = $seq[2];
*/
public function offsetGet($offset) {
if (is_int($offset) and $offset > 0) {
return $this
->get('rdf:_' . $offset);
}
else {
throw new InvalidArgumentException("Container position must be a positive integer");
}
}
/**
* Array Access: set an item at a positon in container using array syntax
*
* Example: $seq[2] = $item;
*
* Warning: creating gaps in the sequence will result in unexpected behavior
*/
public function offsetSet($offset, $value) {
if (is_int($offset) and $offset > 0) {
return $this
->set('rdf:_' . $offset, $value);
}
elseif (is_null($offset)) {
return $this
->append($value);
}
else {
throw new InvalidArgumentException("Container position must be a positive integer");
}
}
/**
* Array Access: delete an item at a specific postion using array syntax
*
* Example: unset($seq[2]);
*
* Warning: creating gaps in the sequence will result in unexpected behavior
*/
public function offsetUnset($offset) {
if (is_int($offset) and $offset > 0) {
return $this
->delete('rdf:_' . $offset);
}
else {
throw new InvalidArgumentException("Container position must be a positive integer");
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EasyRdf_Container:: |
private | property | ||
EasyRdf_Container:: |
public | function | Append an item to the end of the container | |
EasyRdf_Container:: |
public | function | Counts the number of items in the container | |
EasyRdf_Container:: |
public | function | Return the current item in the container | |
EasyRdf_Container:: |
public | function | Return the key / current position in the container | |
EasyRdf_Container:: |
public | function | Move forward to next item in the container | |
EasyRdf_Container:: |
public | function | Array Access: check if a position exists in container using array syntax | |
EasyRdf_Container:: |
public | function | Array Access: get an item at a specified position in container using array syntax | |
EasyRdf_Container:: |
public | function | Array Access: set an item at a positon in container using array syntax | |
EasyRdf_Container:: |
public | function | Array Access: delete an item at a specific postion using array syntax | |
EasyRdf_Container:: |
public | function | Rewind the iterator back to the start of the container (item 1) | |
EasyRdf_Container:: |
public | function | Seek to a specific position in the container | |
EasyRdf_Container:: |
public | function | Checks if current position is valid | |
EasyRdf_Container:: |
public | function |
Create a new container - do not use this directly Overrides EasyRdf_Resource:: |
|
EasyRdf_Resource:: |
protected | property | The Graph that this resource belongs to | |
EasyRdf_Resource:: |
protected | property | The URI for this resource | |
EasyRdf_Resource:: |
public | function | Add values to for a property of the resource | |
EasyRdf_Resource:: |
public | function | Add a literal value as a property of the resource | |
EasyRdf_Resource:: |
public | function | Add a resource as a property of the resource | |
EasyRdf_Resource:: |
public | function | Add one or more rdf:type properties to the resource | |
EasyRdf_Resource:: |
public | function | Get all values for a property | |
EasyRdf_Resource:: |
public | function | Get all literal values for a property of the resource | |
EasyRdf_Resource:: |
public | function | Get all resources for a property of the resource | |
EasyRdf_Resource:: |
protected | function | Throw can exception if the resource does not belong to a graph @ignore | |
EasyRdf_Resource:: |
public | function | Count the number of values for a property of a resource | |
EasyRdf_Resource:: |
public | function | Delete a property (or optionally just a specific value) | |
EasyRdf_Resource:: |
public | function | Return a human readable view of the resource and its properties | |
EasyRdf_Resource:: |
public | function | Return pretty-print view of the resource | |
EasyRdf_Resource:: |
public | function | Get a single value for a property | |
EasyRdf_Resource:: |
public | function | Get the identifier for a blank node | |
EasyRdf_Resource:: |
public | function | Return the graph that this resource belongs to | |
EasyRdf_Resource:: |
public | function | Get a single literal value for a property of the resource | |
EasyRdf_Resource:: |
public | function | Get a single resource value for a property of the resource | |
EasyRdf_Resource:: |
public | function | Returns the URI for the resource. | |
EasyRdf_Resource:: |
public | function | Check to see if a property exists for this resource. | |
EasyRdf_Resource:: |
public | function | Generates an HTML anchor tag, linking to this resource. | |
EasyRdf_Resource:: |
public | function | Check if a resource is of the specified type | |
EasyRdf_Resource:: |
public | function | Check to see if a resource is a blank node. | |
EasyRdf_Resource:: |
public | function | Concatenate all values for a property into a string. | |
EasyRdf_Resource:: |
public | function | Get a human readable label for this resource | |
EasyRdf_Resource:: |
public | function | Perform a load (download of remote URI) of the resource into the graph | |
EasyRdf_Resource:: |
public | function | Gets the local name of the URI of this resource | |
EasyRdf_Resource:: |
public | function | Parse the URI of the resource and return as a ParsedUri object | |
EasyRdf_Resource:: |
public | function | Get a the prefix of the namespace that this resource is part of | |
EasyRdf_Resource:: |
public | function | Get the primary topic of this resource. | |
EasyRdf_Resource:: |
public | function | Get a list of all the shortened property names (qnames) for a resource. | |
EasyRdf_Resource:: |
public | function | Get a list of the full URIs for the properties of this resource. | |
EasyRdf_Resource:: |
public | function | Get a list of the full URIs for the properties that point to this resource. | |
EasyRdf_Resource:: |
public | function | Set value for a property | |
EasyRdf_Resource:: |
public | function | Change the rdf:type property for the resource | |
EasyRdf_Resource:: |
public | function | Get a shortened version of the resources URI. | |
EasyRdf_Resource:: |
public | function | Returns the properties of the resource as an RDF/PHP associative array | |
EasyRdf_Resource:: |
public | function | Get a single type for a resource. | |
EasyRdf_Resource:: |
public | function | Get a single type for a resource, as a resource. | |
EasyRdf_Resource:: |
public | function | Get a list of types for a resource. | |
EasyRdf_Resource:: |
public | function | Get a list of types for a resource, as Resources. | |
EasyRdf_Resource:: |
public | function | Magic method to get a property of a resource | |
EasyRdf_Resource:: |
public | function | Magic method to check if a property exists | |
EasyRdf_Resource:: |
public | function | Magic method to set the value for a property of a resource | |
EasyRdf_Resource:: |
public | function | Magic method to return URI of resource when casted to string | |
EasyRdf_Resource:: |
public | function | Magic method to delete a property of the resource |