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

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