CloudObjects PHP SDK
Installation
The SDK is distributed through packagist.
Install with the following command:
composer require cloudobjects/sdk
Usage
The primary purpose of the SDK is the retrieval of object descriptions from the CloudObjects Core Object API. To do so, you create an instance of the CloudObjects\SDK\ObjectRetriever class. You can use this class directy, but you can also use the static facade (CloudObjects\SDK\ObjectRetrieverFacade) or the global function cloudobjects_get_object(), depending on the architecture of your PHP application and your preferred coding style.
You can use the high-level CloudObjects\SDK\CloudObject interface or the lower-level ML\JsonLD\Node interface (from the sweetrdf/json-ld package) to work with the parsed JSON-LD representation of the object.
Using the ObjectRetriever directly
use CloudObjects\SDK\ObjectRetriever;
use ML\IRI\IRI;
$retriever = new ObjectRetriever;
$object = $retriever->getCloudObject(new IRI('coid://cloudobjects.io'));
echo $object->getLabel();
When no options are passed to the ObjectRetriever, it will initialize with default settings and no authentication, which means that it can only retrieve public triples from public objects. You can authenticate with a CloudObjects namespace (domain name) and the shared secret between this namespace and CloudObjects.
use CloudObjects\SDK\ObjectRetriever;
use ML\IRI\IRI;
$retriever = new ObjectRetriever([
'auth_ns' => 'example.com',
'auth_secret' => 'YOUR_SHARED_SECRET',
]);
$object = $retriever->getCloudObject(new IRI('coid://example.com/PrivateObject'));
// Retrieve the object describing the authenticating namespace itself
$namespace = $retriever->getAuthenticatingNamespaceCloudObject();
echo $namespace->getLabel();
Any production usage should configure a cache; all the caching options are documented here. Other options are documented here.
Using the static facade
use CloudObjects\SDK\ObjectRetriever;
use CloudObjects\SDK\ObjectRetrieverFacade;
use ML\IRI\IRI;
ObjectRetrieverFacade::setObjectRetriever(new ObjectRetriever);
$object = ObjectRetrieverFacade::getCloudObject(new IRI('coid://cloudobjects.io'));
echo $object->getLabel();
Using the global function
The global function uses the static facade, so the facade must be initialized first.
use CloudObjects\SDK\ObjectRetriever;
use CloudObjects\SDK\ObjectRetrieverFacade;
ObjectRetrieverFacade::setObjectRetriever(new ObjectRetriever);
$object = cloudobjects_get_object('coid://cloudobjects.io');
echo $object->getLabel();
Working with the CloudObject interface
$object = $retriever->getCloudObject(new IRI('coid://cloudobjects.io'));
echo $object->getString('http://www.w3.org/2000/01/rdf-schema#comment');
Working with the Node interface
$node = $retriever->getObjectNode(new IRI('coid://cloudobjects.io'));
echo $node->getProperty('http://www.w3.org/2000/01/rdf-schema#comment')->getValue();
License
The PHP SDK is licensed under Mozilla Public License (see LICENSE file).