You are here

public function EasyRdf_Graph::resource in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php \EasyRdf_Graph::resource()

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.

Parameters

string $uri The URI of the resource:

mixed $types RDF type of a new resource (e.g. foaf:Person):

Return value

object EasyRdf_Resource

4 calls to EasyRdf_Graph::resource()
EasyRdf_Graph::arrayToObject in vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Get an EasyRdf_Resource or EasyRdf_Literal object from an associative array. @ignore
EasyRdf_Graph::newBNode in vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Create a new blank node in the graph and return it.
EasyRdf_Graph::resources in vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Get an associative array of all the resources stored in the graph. The keys of the array is the URI of the EasyRdf_Resource.
EasyRdf_Graph::resourcesMatching in vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Get an arry of resources matching a certain property and optional value.

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php, line 129

Class

EasyRdf_Graph
Container for collection of EasyRdf_Resources.

Code

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];
}