Get or create a resource stored in a graph
If the resource did not previously exist, then a new resource will be created. If you provide an RDF type and that type is registered with the EasyRdf_TypeMapper, then the resource will be an instance of the class registered.
If URI is null, then the URI of the graph is used.
string $uri The URI of the resource:
mixed $types RDF type of a new resource (e.g. foaf:Person):
object EasyRdf_Resource
public function resource($uri = null, $types = array()) {
$this
->checkResourceParam($uri, true);
if (!$uri) {
throw new InvalidArgumentException('$uri is null and EasyRdf_Graph object has no URI either.');
}
// Resolve relative URIs
if ($this->parsedUri) {
$uri = $this->parsedUri
->resolve($uri)
->toString();
}
// Add the types
$this
->addType($uri, $types);
// Create resource object if it doesn't already exist
if (!isset($this->resources[$uri])) {
$resClass = $this
->classForResource($uri);
$this->resources[$uri] = new $resClass($uri, $this);
}
return $this->resources[$uri];
}