protected function EasyRdf_Graph::getSingleProperty in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php \EasyRdf_Graph::getSingleProperty()
Get a single value for a property of a resource
@ignore
Parameters
string $resource The URI of the resource (e.g. http://example.com/joe#me):
string $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
1 call to EasyRdf_Graph::getSingleProperty()
- EasyRdf_Graph::get in vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ Graph.php - Get a single value for a property of a resource
File
- vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ Graph.php, line 624
Class
- EasyRdf_Graph
- Container for collection of EasyRdf_Resources.
Code
protected function getSingleProperty($resource, $property, $type = null, $lang = null) {
$this
->checkResourceParam($resource);
$this
->checkSinglePropertyParam($property, $inverse);
// Get an array of values for the property
$values = $this
->propertyValuesArray($resource, $property, $inverse);
if (!isset($values)) {
return null;
}
// Filter the results
$result = null;
if ($type) {
foreach ($values as $value) {
if ($type == 'literal' and $value['type'] == 'literal') {
if ($lang == null or isset($value['lang']) and $value['lang'] == $lang) {
$result = $value;
break;
}
}
elseif ($type == 'resource') {
if ($value['type'] == 'uri' or $value['type'] == 'bnode') {
$result = $value;
break;
}
}
}
}
else {
$result = $values[0];
}
// Convert the internal data structure into a PHP object
return $this
->arrayToObject($result);
}