diff --git a/README.md b/README.md index 24e9200..84ebc38 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,62 @@ 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 to work with the parsed JSON-LD representation of the object. + +### Using the ObjectRetriever directly + +```php +use CloudObjects\SDK\ObjectRetriever; +use ML\IRI\IRI; + +$retriever = new ObjectRetriever; +$object = $retriever->getCloudObject(new IRI('coid://cloudobjects.io')); +echo $object->getLabel(); +``` + +### Using the static facade + +```php +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. + +```php +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 + +```php +$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 + +```php +$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).