Add retriever to CloudObject and allow retrieval of related objects

This commit is contained in:
2026-05-15 10:54:39 +00:00
parent a9689d5a2b
commit 0cb2655494
4 changed files with 45 additions and 6 deletions

View File

@@ -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);
}
}

View File

@@ -196,7 +196,8 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
return null;
}
$object = new CloudObject($coid, $node);
$object = (new CloudObject($coid, $node))
->setObjectRetriever($this);
if ($this->defaultReader) {
// Initialize CloudObject with default reader if it is set