getId(), "COID and Node ID must match."); $this->coid = $coid; $this->node = $node; } /** * Specify a custom NodeReader to use for this CloudObject. * If not set, a default NodeReader will be used. */ public function setReader(NodeReader $reader) : self { $this->reader = $reader; return $this; } private function getReader() : NodeReader { if (!$this->reader) { $this->reader = new NodeReader; } 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. */ public function getCOID() : IRI { return $this->coid; } /** * Get the object node encapsulated in this CloudObject. */ public function getAsNode() : Node { return $this->node; } /** * Get the value of a property as a string. * If the property has multiple values, only the first is returned. */ public function getString($property, string $default = null) : ?string { return $this->getReader()->getFirstValueString($this->node, $property, $default); } /** * Get the value of a property as an integer. * If the property has multiple values, only the first is returned. */ public function getInt($property, int $default = null) : ?int { return $this->getReader()->getFirstValueInt($this->node, $property, $default); } /** * Get the value of a property as a float. * If the property has multiple values, only the first is returned. */ public function getFloat($property, float $default = null) : ?float { return $this->getReader()->getFirstValueFloat($this->node, $property, $default); } /** * Get the value of a property as a boolean. * If the property has multiple values, only the first is returned. */ public function getBool($property, bool $default = null) : ?bool { return $this->getReader()->getFirstValueBool($this->node, $property, $default); } /** * Get the value of a property as an IRI. * If the property has multiple values, only the first is returned. */ public function getIRI($property, IRI $default = null) : ?IRI { return $this->getReader()->getFirstValueIRI($this->node, $property, $default); } /** * Get the value of a property as a Node. * If the property has multiple values, only the first is returned. */ public function getNode($property, Node $default = null) : ?Node { 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); } /** * Get the value of a property and, if it's a COID, retrieve the corresponding object node. */ public function getObjectNode($property) : ?Node { 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->getObjectNode($coid); } }