emstorage / php-sdk
该软件包最新版本(v3.1)没有可用的许可证信息。
v3.1
2020-06-26 15:39 UTC
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-09-24 16:35:16 UTC
README
PHP SDK 用于 http://fr.emstorage.com
安装
composer require emstorage/php-sdk:dev-master
最终会发布一个稳定版本...
创建客户端
使用 Silex
您可以使用服务提供商
<?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,
]
]);
对于每个应用程序,它将创建一个名为 "emstorage.yourAppName" 的服务
或手动
<?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 = []);
使用方法
客户端在 EmStorage 中为每个资源有一个子客户端。 TODO: 为每个资源创建一个文档文件
ObjectClient
- 创建一个文件(如果文件已存在,将抛出异常 - TODO)
/** @var ObjectSummaryInterface $file **/ $file = $emStorage->object->create($path, $content);
- 更新一个文件(如果文件不存在,将抛出异常 - TODO)
/** @var ObjectSummaryInterface $file **/ $file = $emStorage->object->update($path, $content);
- 删除一个文件(如果文件不存在,将抛出异常 - TODO)
$emStorage->object->delete($path);
- 获取文件元数据
/** @var ObjectSummaryInterface $file **/ $file = $emStorage->object->getObject($path);
- 获取列表
/** @var Collection|ObjectSummaryInterface[] $files **/ $files = $emStorage->object->getObjects($offset = 0, $limit = 5);
您还可以使用模型(ObjectSummaryInterface)进行操作
- 创建文件
$file = new EmObject(); $file->setFilename($path); $remoteFile = $emStorage->object->createFromObject($file); // warning: returned $remoteFile is not the same instance as $file, TODO ?
请随意使用您的 IDE 探索客户端,以找到其他创建、获取或删除文件的方法。
模型
ObjectSummaryInterface
在发送文件时,您将与该接口一起工作。
<?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();
}
集合
ObjectSummaryInterface 的集合。
class Collection implements \ArrayAccess, \Countable, \Iterator { }
它还提供 nav 和 links 属性
$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] ? ) */
待续...