Implemented a facade for ObjectRetriever to allow static access
This commit is contained in:
80
CloudObjects/SDK/ObjectRetrieverFacade.php
Normal file
80
CloudObjects/SDK/ObjectRetrieverFacade.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
namespace CloudObjects\SDK;
|
||||
|
||||
use Exception;
|
||||
use ML\IRI\IRI;
|
||||
use ML\JsonLD\Node;
|
||||
|
||||
/**
|
||||
* Static facade for ObjectRetriever. Call setObjectRetriever() once to
|
||||
* initialize; all subsequent static calls are forwarded to that instance.
|
||||
*/
|
||||
class ObjectRetrieverFacade {
|
||||
|
||||
private static ?ObjectRetriever $instance = null;
|
||||
|
||||
public static function setObjectRetriever(ObjectRetriever $retriever) : void {
|
||||
self::$instance = $retriever;
|
||||
}
|
||||
|
||||
private static function getInstance() : ObjectRetriever {
|
||||
if (self::$instance === null)
|
||||
throw new Exception('ObjectRetrieverFacade has not been initialized. Call setObjectRetriever() first.');
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public static function setDefaultReader(NodeReader $reader) : ObjectRetriever {
|
||||
return self::getInstance()->setDefaultReader($reader);
|
||||
}
|
||||
|
||||
public static function getDefaultReader() : NodeReader {
|
||||
return self::getInstance()->getDefaultReader();
|
||||
}
|
||||
|
||||
public static function getClient() {
|
||||
return self::getInstance()->getClient();
|
||||
}
|
||||
|
||||
public static function getCloudObject(IRI $coid) : ?CloudObject {
|
||||
return self::getInstance()->getCloudObject($coid);
|
||||
}
|
||||
|
||||
public static function getObjectNode(IRI $coid) : ?Node {
|
||||
return self::getInstance()->getObjectNode($coid);
|
||||
}
|
||||
|
||||
public static function fetchObjectsInNamespaceWithType(IRI $namespaceCoid, $type) : array {
|
||||
return self::getInstance()->fetchObjectsInNamespaceWithType($namespaceCoid, $type);
|
||||
}
|
||||
|
||||
public static function fetchAllObjectsInNamespace(IRI $namespaceCoid) : array {
|
||||
return self::getInstance()->fetchAllObjectsInNamespace($namespaceCoid);
|
||||
}
|
||||
|
||||
public static function getCOIDListForNamespace(IRI $namespaceCoid) : array {
|
||||
return self::getInstance()->getCOIDListForNamespace($namespaceCoid);
|
||||
}
|
||||
|
||||
public static function getCOIDListForNamespaceWithType(IRI $namespaceCoid, $type) : array {
|
||||
return self::getInstance()->getCOIDListForNamespaceWithType($namespaceCoid, $type);
|
||||
}
|
||||
|
||||
public static function getAttachment(IRI $coid, $filename) {
|
||||
return self::getInstance()->getAttachment($coid, $filename);
|
||||
}
|
||||
|
||||
public static function getAuthenticatingNamespaceObjectNode() : ?Node {
|
||||
return self::getInstance()->getAuthenticatingNamespaceObjectNode();
|
||||
}
|
||||
|
||||
public static function getAuthenticatingNamespaceCloudObject() : ?CloudObject {
|
||||
return self::getInstance()->getAuthenticatingNamespaceCloudObject();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user