Refactored and renamed getAuthenticatingNamespaceObject(), added more type hints
This commit is contained in:
@@ -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' => [
|
||||
|
||||
@@ -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.");
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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' => [
|
||||
|
||||
Reference in New Issue
Block a user