Add retriever to CloudObject and allow retrieval of related objects
This commit is contained in:
@@ -19,7 +19,8 @@ class CloudObject {
|
||||
|
||||
private $coid;
|
||||
private $node;
|
||||
private $reader;
|
||||
private $reader = null;
|
||||
private $retriever = null;
|
||||
|
||||
public function __construct(IRI $coid, Node $node) {
|
||||
Assert::eq((string)$coid, $node->getId(), "COID and Node ID must match.");
|
||||
@@ -45,6 +46,16 @@ class CloudObject {
|
||||
return $this->reader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify an ObjectRetriever to use for retrieval
|
||||
* of related objects.
|
||||
*/
|
||||
public function setObjectRetriever(ObjectRetriever $retriever) : self {
|
||||
$this->retriever = $retriever;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the COID of this object.
|
||||
*/
|
||||
@@ -53,7 +64,7 @@ class CloudObject {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw object node.
|
||||
* Get the object node encapsulated in this CloudObject.
|
||||
*/
|
||||
public function getObjectNode() : Node {
|
||||
return $this->node;
|
||||
@@ -107,4 +118,19 @@ class CloudObject {
|
||||
return $this->getReader()->getFirstValueNode($this->node, $property, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a property and, if it's a COID, retrieve the corresponding CloudObject.
|
||||
*/
|
||||
public function getCloudObject($property) : ?CloudObject {
|
||||
Assert::notNull($this->retriever, "No ObjectRetriever set for CloudObject. Cannot retrieve related object.");
|
||||
|
||||
$coid = $this->getReader()->getFirstValueIRI($this->node, $property);
|
||||
|
||||
if (!($coid instanceof IRI)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->retriever->getCloudObject($coid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user