public function EasyRdf_Graph::get in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php \EasyRdf_Graph::get()
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.
Parameters
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):
Return value
mixed A value associated with the property
6 calls to EasyRdf_Graph::get()
- EasyRdf_Graph::getLiteral in vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ Graph.php - Get a single literal value for a property of a resource
- EasyRdf_Graph::getResource in vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ Graph.php - Get a single resource value for a property of a resource
- EasyRdf_Graph::label in vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ Graph.php - Get a human readable label for a resource
- EasyRdf_Graph::primaryTopic in vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ Graph.php - Get the primary topic of the graph
- EasyRdf_Graph::typeAsResource in vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ Graph.php - Get the resource type of the graph as a EasyRdf_Resource
File
- vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ Graph.php, line 571
Class
- EasyRdf_Graph
- Container for collection of EasyRdf_Resources.
Code
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;
}