class Resource implements ArrayAccess

Class that represents an RDF resource

Properties

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

Methods

__construct($uri, $graph = null)

Constructor

Graph
getGraph()

Return the graph that this resource belongs to

string
getUri()

Returns the URI for the resource.

bool
isBNode()

Check to see if a resource is a blank node.

string
getBNodeId()

Get the identifier for a blank node

string
prefix()

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

string
shorten()

Get a shortened version of the resources URI.

string
localName()

Gets the local name of the URI of this resource

ParsedUri
parseUri()

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

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

Generates an HTML anchor tag, linking to this resource.

array
toRdfPhp()

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

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

Return pretty-print view of the resource

string
__toString()

Magic method to return URI of resource when casted to string

checkHasGraph()

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

int
load(string $format = null)

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

int
delete(string $property, object $value = null)

Delete a property (or optionally just a specific value)

int
add(mixed $property, mixed $value)

Add values to for a property of the resource

int
addLiteral(mixed $property, mixed $values, string $lang = null)

Add a literal value as a property of the resource

int
addResource(mixed $property, mixed $resource2)

Add a resource as a property of the resource

int
set(string $property, mixed $value)

Set value for a property

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

Get a single value for a property

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

Get a single literal value for a property of the resource

getResource(string|array $property)

Get a single resource value for a property of the resource

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

Get all values for a property

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

Get all literal values for a property of the resource

array
allResources(string $property)

Get all resources for a property of the resource

int
countValues(string $property, string $type = null, string $lang = null)

Count the number of values for a property of a resource

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

Concatenate all values for a property into a string.

array
propertyUris()

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

array
properties()

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

array
reversePropertyUris()

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

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

Check to see if a property exists for this resource.

array
types()

Get a list of types for a resource.

string
type()

Get a single type for a resource.

resource
typeAsResource()

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

resource[]
typesAsResources()

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

bool
isA(string $type)

Check if a resource is of the specified type

int
addType(string $types)

Add one or more rdf:type properties to the resource

int
setType(string $type)

Change the rdf:type property for the resource

resource
primaryTopic()

Get the primary topic of this resource.

Literal|null
label(string|null $lang = null)

Get a human readable label for this resource

string
dump(string $format = 'html')

Return a human readable view of the resource and its properties

string
__get(string $name)

Magic method to get a property of a resource

int
__set(string $name, string $value)

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

bool
__isset(string $name)

Magic method to check if a property exists

int
__unset(string $name)

Magic method to delete a property of the resource

bool
offsetExists(mixed $offset)

Whether a offset exists

mixed
offsetGet(mixed $offset)

Offset to retrieve

void
offsetSet(mixed $offset, mixed $value)

Offset to set

void
offsetUnset(mixed $offset)

Offset to unset

Details

at line 63
__construct($uri, $graph = null)

Constructor

  • Please do not call new EasyRdf\Resource() directly *

To create a new resource use the get method in a graph: $resource = $graph->resource('http://www.example.com/');

Parameters

$uri
$graph

at line 88
Graph getGraph()

Return the graph that this resource belongs to

Return Value

Graph

at line 97
string getUri()

Returns the URI for the resource.

Return Value

string

at line 106
bool isBNode()

Check to see if a resource is a blank node.

Return Value

bool

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

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

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

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

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

Exceptions

InvalidArgumentException

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

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

at line 242
string __toString()

Magic method to return URI of resource when casted to string

Return Value

string

at line 252
protected checkHasGraph()

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

@ignore

at line 270
int 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

int

at line 283
int 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

int

at line 299
int 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

int

at line 318
int 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

int

at line 334
int 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

int

at line 352
int 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

int

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

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

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

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

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

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

at line 474
int 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

int

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

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

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

at line 525
array reversePropertyUris()

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

Return Value

array

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

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

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

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

at line 597
resource[] typesAsResources()

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

Return Value

resource[]

Exceptions

Exception

at line 609
bool 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

bool

at line 621
int 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

int

at line 635
int 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

int

at line 647
resource primaryTopic()

Get the primary topic of this resource.

Returns null if no primary topic is available.

Return Value

resource

at line 664
Literal|null 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

Literal|null

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

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

See also

RdfNamespace::setDefault

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

RdfNamespace::setDefault

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

RdfNamespace::setDefault

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

RdfNamespace::setDefault

at line 772
bool offsetExists(mixed $offset)

Whether a offset exists

The return value will be casted to boolean if non-boolean was returned.

Example: if(isset($resource['rdfs:label'])) { }

Parameters

mixed $offset An offset to check for.

Return Value

bool

at line 789
mixed offsetGet(mixed $offset)

Offset to retrieve

Example: $label = $resource['rdfs:label'];

Parameters

mixed $offset The offset to retrieve.

Return Value

mixed

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

Offset to set

Example: $resource['rdfs:label'] = 'label';

Parameters

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

Return Value

void

at line 824
void offsetUnset(mixed $offset)

Offset to unset

Example: unset($resource['rdfs:label']);

Parameters

mixed $offset The offset to unset.

Return Value

void