From da0ddd572e5f7d390dbf276ae85ae59b7fccdd81 Mon Sep 17 00:00:00 2001 From: Lukas Rosenstock Date: Tue, 2 Jun 2026 12:32:09 +0000 Subject: [PATCH] Refactored and renamed getAuthenticatingNamespaceObject(), added more type hints --- CloudObjects/SDK/Common/CryptoHelper.php | 2 +- CloudObjects/SDK/ObjectRetriever.php | 54 +++++++++++++++----- CloudObjects/SDK/WebAPI/APIClientFactory.php | 2 +- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/CloudObjects/SDK/Common/CryptoHelper.php b/CloudObjects/SDK/Common/CryptoHelper.php index fe231b8..32bcdaf 100644 --- a/CloudObjects/SDK/Common/CryptoHelper.php +++ b/CloudObjects/SDK/Common/CryptoHelper.php @@ -60,7 +60,7 @@ class CryptoHelper { $this->objectRetriever = $objectRetriever; $this->namespace = isset($namespaceCoid) ? $objectRetriever->getObjectNode($namespaceCoid) - : $objectRetriever->getAuthenticatingNamespaceObject(); + : $objectRetriever->getAuthenticatingNamespaceObjectNode(); $this->reader = new NodeReader([ 'prefixes' => [ diff --git a/CloudObjects/SDK/ObjectRetriever.php b/CloudObjects/SDK/ObjectRetriever.php index 26e3830..80eb844 100644 --- a/CloudObjects/SDK/ObjectRetriever.php +++ b/CloudObjects/SDK/ObjectRetriever.php @@ -7,7 +7,8 @@ namespace CloudObjects\SDK; use DateTime, Exception; -use ML\IRI\IRI, ML\JsonLD\JsonLD; +use ML\IRI\IRI; +use ML\JsonLD\JsonLD, ML\JsonLD\Node; use Psr\Log\LoggerInterface, Psr\Log\LoggerAwareTrait; use GuzzleHttp\ClientInterface, GuzzleHttp\Client, GuzzleHttp\HandlerStack; use GuzzleHttp\Exception\RequestException; @@ -205,7 +206,7 @@ class ObjectRetriever implements CustomCacheAndLogInterface { /** * Get an object description and return a CloudObject. */ - public function getCloudObject(IRI $coid) { + public function getCloudObject(IRI $coid) : CloudObject { $node = $this->getObjectNode($coid); if (!$node) { // Object not found @@ -238,7 +239,7 @@ class ObjectRetriever implements CustomCacheAndLogInterface { * @param IRI $coid COID of the object * @return Node|null */ - public function getObjectNode(IRI $coid) { + public function getObjectNode(IRI $coid) : Node { if (!COIDParser::isValidCOID($coid)) throw new Exception("Not a valid COID."); @@ -517,21 +518,46 @@ class ObjectRetriever implements CustomCacheAndLogInterface { return $fileContent; } - /** - * Retrieve the object that describes the namespace provided with the "auth_ns" - * configuration option. - * - * @return Node - */ - public function getAuthenticatingNamespaceObject() { + private function assertAuthenticatingNamespaceAndGetId() : IRI { if (!isset($this->options['auth_ns'])) - throw new Exception("Missing 'auth_ns' configuration option."); + throw new InvalidSDKConfigurationException("Missing 'auth_ns' configuration option."); $namespaceCoid = COIDParser::fromString($this->options['auth_ns']); if (COIDParser::getType($namespaceCoid) != COIDParser::COID_ROOT) - throw new Exception("The 'auth_ns' configuration option is not a valid namespace/root COID."); - - return $this->getObject($namespaceCoid); + throw new InvalidSDKConfigurationException("The 'auth_ns' configuration option is not a valid namespace/root COID."); + + return $namespaceCoid; + } + + /** + * Retrieve the object node that describes the namespace + * provided with the "auth_ns" configuration option. + * + * @deprecated Use getAuthenticatingNamespaceObjectNode() instead + * @return Node + */ + public function getAuthenticatingNamespaceObject() : Node { + return $this->getObject($this->assertAuthenticatingNamespaceAndGetId()); + } + + /** + * Retrieve the object node that describes the namespace + * provided with the "auth_ns" configuration option. + * + * @return Node + */ + public function getAuthenticatingNamespaceObjectNode() : Node { + return $this->getObject($this->assertAuthenticatingNamespaceAndGetId()); + } + + /** + * Retrieve the CloudObject that describes the namespace + * provided with the "auth_ns" configuration option. + * + * @return CloudObject + */ + public function getAuthenticatingNamespaceCloudObject() : CloudObject { + return $this->getCloudObject($this->assertAuthenticatingNamespaceAndGetId()); } } \ No newline at end of file diff --git a/CloudObjects/SDK/WebAPI/APIClientFactory.php b/CloudObjects/SDK/WebAPI/APIClientFactory.php index 4e1b5f0..58a82c0 100644 --- a/CloudObjects/SDK/WebAPI/APIClientFactory.php +++ b/CloudObjects/SDK/WebAPI/APIClientFactory.php @@ -221,7 +221,7 @@ class APIClientFactory { $this->objectRetriever = $objectRetriever; $this->namespace = isset($namespaceCoid) ? $objectRetriever->getObjectNode($namespaceCoid) - : $objectRetriever->getAuthenticatingNamespaceObject(); + : $objectRetriever->getAuthenticatingNamespaceObjectNode(); $this->reader = new NodeReader([ 'prefixes' => [