Refactored and renamed getAuthenticatingNamespaceObject(), added more type hints

This commit is contained in:
2026-06-02 12:32:09 +00:00
parent 5f5a31df68
commit da0ddd572e
3 changed files with 42 additions and 16 deletions

View File

@@ -60,7 +60,7 @@ class CryptoHelper {
$this->objectRetriever = $objectRetriever; $this->objectRetriever = $objectRetriever;
$this->namespace = isset($namespaceCoid) $this->namespace = isset($namespaceCoid)
? $objectRetriever->getObjectNode($namespaceCoid) ? $objectRetriever->getObjectNode($namespaceCoid)
: $objectRetriever->getAuthenticatingNamespaceObject(); : $objectRetriever->getAuthenticatingNamespaceObjectNode();
$this->reader = new NodeReader([ $this->reader = new NodeReader([
'prefixes' => [ 'prefixes' => [

View File

@@ -7,7 +7,8 @@
namespace CloudObjects\SDK; namespace CloudObjects\SDK;
use DateTime, Exception; 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 Psr\Log\LoggerInterface, Psr\Log\LoggerAwareTrait;
use GuzzleHttp\ClientInterface, GuzzleHttp\Client, GuzzleHttp\HandlerStack; use GuzzleHttp\ClientInterface, GuzzleHttp\Client, GuzzleHttp\HandlerStack;
use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\RequestException;
@@ -205,7 +206,7 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
/** /**
* Get an object description and return a CloudObject. * Get an object description and return a CloudObject.
*/ */
public function getCloudObject(IRI $coid) { public function getCloudObject(IRI $coid) : CloudObject {
$node = $this->getObjectNode($coid); $node = $this->getObjectNode($coid);
if (!$node) { if (!$node) {
// Object not found // Object not found
@@ -238,7 +239,7 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
* @param IRI $coid COID of the object * @param IRI $coid COID of the object
* @return Node|null * @return Node|null
*/ */
public function getObjectNode(IRI $coid) { public function getObjectNode(IRI $coid) : Node {
if (!COIDParser::isValidCOID($coid)) if (!COIDParser::isValidCOID($coid))
throw new Exception("Not a valid COID."); throw new Exception("Not a valid COID.");
@@ -517,21 +518,46 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
return $fileContent; return $fileContent;
} }
/** private function assertAuthenticatingNamespaceAndGetId() : IRI {
* Retrieve the object that describes the namespace provided with the "auth_ns"
* configuration option.
*
* @return Node
*/
public function getAuthenticatingNamespaceObject() {
if (!isset($this->options['auth_ns'])) 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']); $namespaceCoid = COIDParser::fromString($this->options['auth_ns']);
if (COIDParser::getType($namespaceCoid) != COIDParser::COID_ROOT) if (COIDParser::getType($namespaceCoid) != COIDParser::COID_ROOT)
throw new Exception("The 'auth_ns' configuration option is not a valid namespace/root COID."); throw new InvalidSDKConfigurationException("The 'auth_ns' configuration option is not a valid namespace/root COID.");
return $this->getObject($namespaceCoid); 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());
} }
} }

View File

@@ -221,7 +221,7 @@ class APIClientFactory {
$this->objectRetriever = $objectRetriever; $this->objectRetriever = $objectRetriever;
$this->namespace = isset($namespaceCoid) $this->namespace = isset($namespaceCoid)
? $objectRetriever->getObjectNode($namespaceCoid) ? $objectRetriever->getObjectNode($namespaceCoid)
: $objectRetriever->getAuthenticatingNamespaceObject(); : $objectRetriever->getAuthenticatingNamespaceObjectNode();
$this->reader = new NodeReader([ $this->reader = new NodeReader([
'prefixes' => [ 'prefixes' => [