Get a single value for a property of a resource
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.
string $resource The URI of the resource (e.g. http://example.com/joe#me):
string $propertyPath A valid property path:
string $type The type of value to filter by (e.g. literal or resource):
string $lang The language to filter by (e.g. en):
mixed A value associated with the property
public function get($resource, $propertyPath, $type = null, $lang = null) {
$this
->checkResourceParam($resource);
if (is_object($propertyPath) and $propertyPath instanceof EasyRdf_Resource) {
return $this
->getSingleProperty($resource, $propertyPath
->getUri(), $type, $lang);
}
elseif (is_string($propertyPath) and preg_match('|^(\\^?)<(.+)>|', $propertyPath, $matches)) {
return $this
->getSingleProperty($resource, "{$matches[1]}{$matches[2]}", $type, $lang);
}
elseif ($propertyPath === null or !is_string($propertyPath)) {
throw new InvalidArgumentException("\$propertyPath should be a string or EasyRdf_Resource and cannot be null");
}
elseif ($propertyPath === '') {
throw new InvalidArgumentException("\$propertyPath cannot be an empty string");
}
// Loop through each component in the path
foreach (explode('/', $propertyPath) as $part) {
// Stop if we come to a literal
if ($resource instanceof EasyRdf_Literal) {
return null;
}
// Try each of the alternative paths
foreach (explode('|', $part) as $p) {
$res = $this
->getSingleProperty($resource, $p, $type, $lang);
if ($res) {
break;
}
}
// Stop if nothing was found
$resource = $res;
if (!$resource) {
break;
}
}
return $resource;
}