class Collection extends Resource implements ArrayAccess, Countable, SeekableIterator

Sub-class of EasyRdf\Resource that represents an RDF collection (rdf:List)

This class can be used to iterate through a collection of items.

Note that items are numbered from 1 (not 0) for consistency with RDF Containers.

Properties

protected $uri The URI for this resource from Resource
protected $graph The Graph that this resource belongs to from Resource

Methods

__construct($uri, $graph)

Create a new collection - do not use this directly

getGraph()

Return the graph that this resource belongs to

from Resource
string
getUri()

Returns the URI for the resource.

from Resource
bool
isBNode()

Check to see if a resource is a blank node.

from Resource
string
getBNodeId()

Get the identifier for a blank node

from Resource
string
prefix()

Get a the prefix of the namespace that this resource is part of

from Resource
string
shorten()

Get a shortened version of the resources URI.

from Resource
string
localName()

Gets the local name of the URI of this resource

from Resource
parseUri()

Parse the URI of the resource and return as a ParsedUri object

from Resource
string
htmlLink(string $text = null, array $options = array())

Generates an HTML anchor tag, linking to this resource.

from Resource
array
toRdfPhp()

Returns the properties of the resource as an RDF/PHP associative array

from Resource
string
dumpValue(string $format = 'html', string $color = 'blue')

Return pretty-print view of the resource

from Resource
string
__toString()

Magic method to return URI of resource when casted to string

from Resource
checkHasGraph()

Throw can exception if the resource does not belong to a graph

from Resource
integer
load(string $format = null)

Perform a load (download of remote URI) of the resource into the graph

from Resource
integer
delete(string $property, object $value = null)

Delete a property (or optionally just a specific value)

from Resource
integer
add(mixed $property, mixed $value)

Add values to for a property of the resource

from Resource
integer
addLiteral(mixed $property, mixed $values, string $lang = null)

Add a literal value as a property of the resource

from Resource
integer
addResource(mixed $property, mixed $resource2)

Add a resource as a property of the resource

from Resource
integer
set(string $property, mixed $value)

Set value for a property

from Resource
mixed
get(string|array $property, string $type = null, string $lang = null)

Get a single value for a property

from Resource
getLiteral(string|array $property, string $lang = null)

Get a single literal value for a property of the resource

from Resource
getResource(string|array $property)

Get a single resource value for a property of the resource

from Resource
array
all(string $property, string $type = null, string $lang = null)

Get all values for a property

from Resource
array
allLiterals(string $property, string $lang = null)

Get all literal values for a property of the resource

from Resource
array
allResources(string $property)

Get all resources for a property of the resource

from Resource
integer
countValues(string $property, string $type = null, string $lang = null)

Count the number of values for a property of a resource

from Resource
string
join(string $property, string $glue = ' ', string $lang = null)

Concatenate all values for a property into a string.

from Resource
array
propertyUris()

Get a list of the full URIs for the properties of this resource.

from Resource
array
properties()

Get a list of all the shortened property names (qnames) for a resource.

from Resource
array
reversePropertyUris()

Get a list of the full URIs for the properties that point to this resource.

from Resource
bool
hasProperty(string $property, mixed $value = null)

Check to see if a property exists for this resource.

from Resource
array
types()

Get a list of types for a resource.

from Resource
string
type()

Get a single type for a resource.

from Resource
Resource
typeAsResource()

Get a single type for a resource, as a resource.

from Resource
Resource[]
typesAsResources()

Get a list of types for a resource, as EasyRdf\Resource

from Resource
boolean
isA(string $type)

Check if a resource is of the specified type

from Resource
integer
addType(string $types)

Add one or more rdf:type properties to the resource

from Resource
integer
setType(string $type)

Change the rdf:type property for the resource

from Resource
Resource
primaryTopic()

Get the primary topic of this resource.

from Resource
string
label(string|null $lang = null)

Get a human readable label for this resource

from Resource
string
dump(string $format = 'html')

Return a human readable view of the resource and its properties

from Resource
string
__get(string $name)

Magic method to get a property of a resource

from Resource
int
__set(string $name, string $value)

Magic method to set the value for a property of a resource

from Resource
bool
__isset(string $name)

Magic method to check if a property exists

from Resource
int
__unset(string $name)

Magic method to delete a property of the resource

from Resource
boolean
offsetExists(mixed $offset)

Array Access: check if a position exists in collection using array syntax

mixed
offsetGet(mixed $offset)

Array Access: get an item at a specified position in collection using array syntax

void
offsetSet(mixed $offset, mixed $value)

Array Access: set an item at a positon in collection using array syntax

void
offsetUnset(mixed $offset)

Array Access: delete an item at a specific postion using array syntax

seek(integer $position)

Seek to a specific position in the container

rewind()

Rewind the iterator back to the start of the collection

mixed
current()

Return the current item in the collection

int
key()

Return the key / current position in the collection

next()

Move forward to next item in the collection

bool
valid()

Checks if current position is valid

array
getCollectionNode(integer $offset)

Get a node for a particular offset into the collection

integer
count()

Counts the number of items in the collection

integer
append(mixed $value)

Append an item to the end of the collection

Details

at line 60
__construct($uri, $graph)

Create a new collection - do not use this directly

Parameters

$uri
$graph

in Resource at line 88
Graph getGraph()

Return the graph that this resource belongs to

Return Value

Graph

in Resource at line 97
string getUri()

Returns the URI for the resource.

Return Value

string URI of this resource.

in Resource at line 106
bool isBNode()

Check to see if a resource is a blank node.

Return Value

bool True if this resource is a blank node.

in Resource at line 121
string getBNodeId()

Get the identifier for a blank node

Returns null if the resource is not a blank node.

Return Value

string The identifer for the bnode

in Resource at line 137
string prefix()

Get a the prefix of the namespace that this resource is part of

This method will return null the resource isn't part of any registered namespace.

Return Value

string The namespace prefix of the resource (e.g. foaf)

in Resource at line 149
string shorten()

Get a shortened version of the resources URI.

This method will return the full URI if the resource isn't part of any registered namespace.

Return Value

string The shortened URI of this resource (e.g. foaf:name)

in Resource at line 161
string localName()

Gets the local name of the URI of this resource

The local name is defined as the part of the URI string after the last occurrence of the '#', ':' or '/' character.

Return Value

string The local name

in Resource at line 172
ParsedUri parseUri()

Parse the URI of the resource and return as a ParsedUri object

Return Value

ParsedUri

Generates an HTML anchor tag, linking to this resource.

If no text is given, then the URI also uses as the link text.

Parameters

string $text Text for the link.
array $options Associative array of attributes for the anchor tag

Return Value

string The HTML link string

Exceptions

InvalidArgumentException

in Resource at line 217
array toRdfPhp()

Returns the properties of the resource as an RDF/PHP associative array

For example: array('type' => 'uri', 'value' => 'http://www.example.com/')

Return Value

array The properties of the resource

in Resource at line 233
string dumpValue(string $format = 'html', string $color = 'blue')

Return pretty-print view of the resource

Parameters

string $format Either 'html' or 'text'
string $color The colour of the text

Return Value

string

in Resource at line 242
string __toString()

Magic method to return URI of resource when casted to string

Return Value

string The URI of the resource

in Resource at line 252
protected checkHasGraph()

Throw can exception if the resource does not belong to a graph

@ignore

in Resource at line 270
integer load(string $format = null)

Perform a load (download of remote URI) of the resource into the graph

The document type is optional but should be specified if it can't be guessed or got from the HTTP headers.

Parameters

string $format Optional format of the data (eg. rdfxml)

Return Value

integer

in Resource at line 283
integer delete(string $property, object $value = null)

Delete a property (or optionally just a specific value)

Parameters

string $property The name of the property (e.g. foaf:name)
object $value The value to delete (null to delete all values)

Return Value

integer

in Resource at line 299
integer add(mixed $property, mixed $value)

Add values to for a property of the resource

Example: $resource->add('prefix:property', 'value');

Parameters

mixed $property The property name
mixed $value The value for the property

Return Value

integer The number of values added (1 or 0)

in Resource at line 318
integer addLiteral(mixed $property, mixed $values, string $lang = null)

Add a literal value as a property of the resource

The value can either be a single value or an array of values.

Example: $resource->add('dc:title', 'Title of Page');

Parameters

mixed $property The property name
mixed $values The value or values for the property
string $lang The language of the literal

Return Value

integer The number of values added

in Resource at line 334
integer addResource(mixed $property, mixed $resource2)

Add a resource as a property of the resource

Example: $bob->add('foaf:knows', 'http://example.com/alice');

Parameters

mixed $property The property name
mixed $resource2 The resource to be the value of the property

Return Value

integer The number of values added (1 or 0)

in Resource at line 352
integer set(string $property, mixed $value)

Set value for a property

The new value(s) will replace the existing values for the property. The name of the property should be a string. If you set a property to null or an empty array, then the property will be deleted.

Parameters

string $property The name of the property (e.g. foaf:name)
mixed $value The value for the property.

Return Value

integer The number of values added (1 or 0)

in Resource at line 374
mixed get(string|array $property, string $type = null, string $lang = null)

Get a single value for a property

If multiple values are set for a property then the value returned may be arbitrary.

If $property is an array, then the first item in the array that matches a property that exists is returned.

This method will return null if the property does not exist.

Parameters

string|array $property The name of the property (e.g. foaf:name)
string $type The type of value to filter by (e.g. literal or resource)
string $lang The language to filter by (e.g. en)

Return Value

mixed A value associated with the property

in Resource at line 393
Literal getLiteral(string|array $property, string $lang = null)

Get a single literal value for a property of the resource

If multiple values are set for a property then the value returned may be arbitrary.

This method will return null if there is not literal value for the property.

Parameters

string|array $property The name of the property (e.g. foaf:name)
string $lang The language to filter by (e.g. en)

Return Value

Literal Literal value associated with the property

in Resource at line 411
Resource getResource(string|array $property)

Get a single resource value for a property of the resource

If multiple values are set for a property then the value returned may be arbitrary.

This method will return null if there is not resource for the property.

Parameters

string|array $property The name of the property (e.g. foaf:name)

Return Value

Resource Resource associated with the property

in Resource at line 427
array all(string $property, string $type = null, string $lang = null)

Get all values for a property

This method will return an empty array if the property does not exist.

Parameters

string $property The name of the property (e.g. foaf:name)
string $type The type of value to filter by (e.g. literal)
string $lang The language to filter by (e.g. en)

Return Value

array An array of values associated with the property

in Resource at line 443
array allLiterals(string $property, string $lang = null)

Get all literal values for a property of the resource

This method will return an empty array if the resource does not has any literal values for that property.

Parameters

string $property The name of the property (e.g. foaf:name)
string $lang The language to filter by (e.g. en)

Return Value

array An array of values associated with the property

in Resource at line 458
array allResources(string $property)

Get all resources for a property of the resource

This method will return an empty array if the resource does not has any resources for that property.

Parameters

string $property The name of the property (e.g. foaf:name)

Return Value

array An array of values associated with the property

in Resource at line 474
integer countValues(string $property, string $type = null, string $lang = null)

Count the number of values for a property of a resource

This method will return 0 if the property does not exist.

Parameters

string $property The name of the property (e.g. foaf:name)
string $type The type of value to filter by (e.g. literal)
string $lang The language to filter by (e.g. en)

Return Value

integer The number of values associated with the property

in Resource at line 491
string join(string $property, string $glue = ' ', string $lang = null)

Concatenate all values for a property into a string.

The default is to join the values together with a space character. This method will return an empty string if the property does not exist.

Parameters

string $property The name of the property (e.g. foaf:name)
string $glue The string to glue the values together with.
string $lang The language to filter by (e.g. en)

Return Value

string Concatenation of all the values.

in Resource at line 503
array propertyUris()

Get a list of the full URIs for the properties of this resource.

This method will return an empty array if the resource has no properties.

Return Value

array Array of full URIs

in Resource at line 515
array properties()

Get a list of all the shortened property names (qnames) for a resource.

This method will return an empty array if the resource has no properties.

Return Value

array Array of shortened URIs

in Resource at line 525
array reversePropertyUris()

Get a list of the full URIs for the properties that point to this resource.

Return Value

array Array of full property URIs

in Resource at line 542
bool hasProperty(string $property, mixed $value = null)

Check to see if a property exists for this resource.

This method will return true if the property exists. If the value parameter is given, then it will only return true if the value also exists for that property.

Parameters

string $property The name of the property (e.g. foaf:name)
mixed $value An optional value of the property

Return Value

bool True if value the property exists.

in Resource at line 555
array types()

Get a list of types for a resource.

The types will each be a shortened URI as a string. This method will return an empty array if the resource has no types.

Return Value

array All types assocated with the resource (e.g. foaf:Person)

in Resource at line 570
string type()

Get a single type for a resource.

The type will be a shortened URI as a string. If the resource has multiple types then the type returned may be arbitrary. This method will return null if the resource has no type.

Return Value

string A type assocated with the resource (e.g. foaf:Person)

in Resource at line 585
Resource typeAsResource()

Get a single type for a resource, as a resource.

The type will be returned as an EasyRdf\Resource. If the resource has multiple types then the type returned may be arbitrary. This method will return null if the resource has no type.

Return Value

Resource A type assocated with the resource.

in Resource at line 597
Resource[] typesAsResources()

Get a list of types for a resource, as EasyRdf\Resource

Return Value

Resource[]

Exceptions

Exception

in Resource at line 609
boolean isA(string $type)

Check if a resource is of the specified type

Parameters

string $type The type to check (e.g. foaf:Person)

Return Value

boolean True if resource is of specified type.

in Resource at line 621
integer addType(string $types)

Add one or more rdf:type properties to the resource

Parameters

string $types One or more types to add (e.g. foaf:Person)

Return Value

integer The number of types added

in Resource at line 635
integer setType(string $type)

Change the rdf:type property for the resource

Note that the PHP class of the resource will not change.

Parameters

string $type The new type (e.g. foaf:Person)

Return Value

integer The number of types added

in Resource at line 647
Resource primaryTopic()

Get the primary topic of this resource.

Returns null if no primary topic is available.

Return Value

Resource The primary topic of this resource.

in Resource at line 664
string label(string|null $lang = null)

Get a human readable label for this resource

This method will check a number of properties for the resource (in the order: skos:prefLabel, rdfs:label, foaf:name, dc:title) and return an approriate first that is available. If no label is available then it will return null.

Parameters

string|null $lang

Return Value

string A label for the resource.

in Resource at line 679
string dump(string $format = 'html')

Return a human readable view of the resource and its properties

This method is intended to be a debugging aid and will print a resource and its properties.

Parameters

string $format Either 'html' or 'text'

Return Value

string

in Resource at line 698
string __get(string $name)

Magic method to get a property of a resource

Note that only properties in the default namespace can be accessed in this way.

Example: $value = $resource->title;

Parameters

string $name The name of the property

Return Value

string A single value for the named property

See also

EasyRdf\RdfNamespace::setDefault()

in Resource at line 717
int __set(string $name, string $value)

Magic method to set the value for a property of a resource

Note that only properties in the default namespace can be accessed in this way.

Example: $resource->title = 'Title';

Parameters

string $name The name of the property
string $value The value for the property

Return Value

int

See also

EasyRdf\RdfNamespace::setDefault()

in Resource at line 735
bool __isset(string $name)

Magic method to check if a property exists

Note that only properties in the default namespace can be accessed in this way.

Example: if (isset($resource->title)) { blah(); }

Parameters

string $name The name of the property

Return Value

bool

See also

EasyRdf\RdfNamespace::setDefault()

in Resource at line 753
int __unset(string $name)

Magic method to delete a property of the resource

Note that only properties in the default namespace can be accessed in this way.

Example: unset($resource->title);

Parameters

string $name The name of the property

Return Value

int

See also

EasyRdf\RdfNamespace::setDefault()

at line 228
boolean offsetExists(mixed $offset)

Array Access: check if a position exists in collection using array syntax

Example: isset($list[2])

Parameters

mixed $offset An offset to check for.

Return Value

boolean true on success or false on failure.

at line 244
mixed offsetGet(mixed $offset)

Array Access: get an item at a specified position in collection using array syntax

Example: $item = $list[2];

Parameters

mixed $offset The offset to retrieve.

Return Value

mixed Can return all value types.

at line 263
void offsetSet(mixed $offset, mixed $value)

Array Access: set an item at a positon in collection using array syntax

Example: $list[2] = $item;

Parameters

mixed $offset The offset to assign the value to.
mixed $value The value to set.

Return Value

void

at line 298
void offsetUnset(mixed $offset)

Array Access: delete an item at a specific postion using array syntax

Example: unset($seq[2]);

Parameters

mixed $offset The offset to unset.

Return Value

void

at line 76
seek(integer $position)

Seek to a specific position in the container

The first item is postion 1

Parameters

integer $position The position in the container to seek to

Exceptions

OutOfBoundsException
InvalidArgumentException

at line 98
rewind()

Rewind the iterator back to the start of the collection

at line 108
mixed current()

Return the current item in the collection

Return Value

mixed The current item

at line 123
int key()

Return the key / current position in the collection

Note: the first item is number 1

Return Value

int The current position

at line 131
next()

Move forward to next item in the collection

at line 145
bool valid()

Checks if current position is valid

Return Value

bool True if the current position is valid

at line 169
array getCollectionNode(integer $offset)

Get a node for a particular offset into the collection

This function may not return the item you requested, if it does not exist. Please check the $postion parameter returned.

If the offset is null, then the last node in the collection (before rdf:nil) will be returned.

Parameters

integer $offset The offset into the collection (or null)

Return Value

array $node, $postion The node object and postion of the node

at line 188
integer count()

Counts the number of items in the collection

Note that this is an slow method - it is more efficient to use the iterator interface, if you can.

Return Value

integer The number of items in the collection

at line 205
integer append(mixed $value)

Append an item to the end of the collection

Parameters

mixed $value The value to append

Return Value

integer The number of values appended (1 or 0)