PHP code example of emstorage / php-sdk

1. Go to this page and download the library: Download emstorage/php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

emstorage / php-sdk example snippets


/** @var ObjectSummaryInterface $file **/
$file = $emStorage->object->create($path, $content);

/** @var ObjectSummaryInterface $file **/
$file = $emStorage->object->update($path, $content);

$emStorage->object->delete($path);

/** @var ObjectSummaryInterface $file **/
$file = $emStorage->object->getObject($path);

/** @var Collection|ObjectSummaryInterface[] $files **/
$files = $emStorage->object->getObjects($offset = 0, $limit = 5);

$file = new EmObject();
$file->setFilename($path);
$remoteFile = $emStorage->object->createFromObject($file);
// warning: returned $remoteFile is not the same instance as $file, TODO ?

class Collection implements \ArrayAccess, \Countable, \Iterator
{
}

$files = $emStorage->object->getObjects();

print_r($files->getNav());

/*
Array
(
    [total] => 38
    [count] => 5
    [offset] => 0
    [limit] => 5
    // TODO need [totalPage] ?
)
*/

print_r($files->getLinks());

/*
Array
(
    [prev] => 
    [next] => /objects?offset=5&limit=5
    // TODO need [nextOffset] ?
)
*/

composer 

 

use Emonsite\Emstorage\PhpSdk\Bridge as EmStorageServiceProvider;

$app->register(new EmStorageServiceProvider(), [
    'emstorage.applications' => [
        'yourAppName' => [
            'public_key' => 'appPublicKey',
            'private_key' => 'appPrivateKey',
        ]
    ],
    'guzzle.options' => [
        'debug' => false,
    ]
]);

 

use Awelty\Component\Security\HmacSignatureProvider;
use Emonsite\Emstorage\PhpSdk\Client;

// Emstorage use hmac authentification with sha1 as algo
$signatureProvider = new HmacSignatureProvider($publicKey, $privateKey, 'sha1');

// create as many clients as you need (typically one per EmStorageApplication)
$emStorage = new Client($authenticator, $someGuzzleConfig = []);



interface ObjectSummaryInterface
{
    /**
     * @return string
     */
    public function getId();

    /**
     * @return string
     */
    public function getFilename();

    /**
     * @return string
     */
    public function getPublicUrl();

    /**
     * @return string
     */
    public function getMime();

    /**
     * @return float
     */
    public function getSize();

    /**
     * @return string
     */
    public function getSizeHuman();

    /**
     * @return array
     */
    public function getMeta();

}