emstorage / php-sdk
Installs: 25 872
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 2
Requires
- php: ^7.3
- ext-json: *
- awelty/security: dev-master
- symfony/cache: ^5.0
- symfony/http-client: ^5.0
- symfony/mime: ^5.0
- symfony/property-access: ^5.0
- symfony/property-info: ^5.0
- symfony/serializer: ^5.0
Requires (Dev)
- league/flysystem: ^1.0
- phpunit/phpunit: ^8.5
- symfony/var-dumper: ^5.0
Suggests
- league/flysystem: For using Flysystem adapter
This package is auto-updated.
Last update: 2024-12-24 17:23:20 UTC
README
PHP SDK for http://fr.emstorage.com
Install
composer require emstorage/php-sdk:dev-master
A stable version will eventually be released one day...
Create a client
With Silex
You can use the service provider:
<?php
use Emonsite\Emstorage\PhpSdk\Bridge as EmStorageServiceProvider;
$app->register(new EmStorageServiceProvider(), [
'emstorage.applications' => [
'yourAppName' => [
'public_key' => 'appPublicKey',
'private_key' => 'appPrivateKey',
]
],
'guzzle.options' => [
'debug' => false,
]
]);
For each applications it will create a service named "emstorage.yourAppName"
Or manually
<?php
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 = []);
Usage
The client has one subclient per resource in EmStorage. TODO: one doc file per resource
ObjectClient
- Create a file (it will throw an exception if the file already exist - TODO)
/** @var ObjectSummaryInterface $file **/ $file = $emStorage->object->create($path, $content);
- Update a file (it will throw an exception if the file doesn't exist - TODO)
/** @var ObjectSummaryInterface $file **/ $file = $emStorage->object->update($path, $content);
- Delete a file (it will throw an exception if the file doesn't exist - TODO)
$emStorage->object->delete($path);
- Get a file metadatas
/** @var ObjectSummaryInterface $file **/ $file = $emStorage->object->getObject($path);
- Get a list
/** @var Collection|ObjectSummaryInterface[] $files **/ $files = $emStorage->object->getObjects($offset = 0, $limit = 5);
You also can work with models (ObjectSummaryInterface)
- Create a file
$file = new EmObject(); $file->setFilename($path); $remoteFile = $emStorage->object->createFromObject($file); // warning: returned $remoteFile is not the same instance as $file, TODO ?
Feel free to exlore the client with your IDE to find some other methods to create, get or delete file from object or objectId.
Models
ObjectSummaryInterface
This is the interface you work with when you send files.
<?php
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();
}
Collection
A collection of ObjectSummaryInterface.
class Collection implements \ArrayAccess, \Countable, \Iterator { }
It also provide nav and links properties:
$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] ? ) */
To be continued...