定制 bag/digitalocean-spaces-helpers 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bag/digitalocean-spaces-helpers

Composer 安装命令:

composer require bag/digitalocean-spaces-helpers

包简介

Helper classes to interact with DigitalOcean spaces object storage using the AWS S3 SDK.

README 文档

README

Helper classes to interact with DigitalOcean spaces object storage using the AWS S3 SDK and Symfony HttpClient.

This library provides common functionality in regards to creating, deleting, and listing Spaces and objects. This library will also facilitate uploading and downloading objects.

This library is fairly new and the api for various methods could change in the upcoming future. I will do my best to document all changes and not introduce breaking changes without notice.

Upcoming

  • Usage examples.
  • Discontinuing use of AWS S3 SDK and implementing fully with http api instead

Classes

BAG\Spaces\Client

Main client class that can be used to manage spaces and objects.

Constants

  • ACL_PUBLIC = 'public-read'
  • ACL_PRIVATE = 'private'

constructor($key, $secret, $region)

Name Type Optional Description
$key string false Spaces api key
$secret string false Spaces api secret
$region string false Spaces region, eg. nyc1

createSpace($name)

Create space.

Returns true if space was created, false if it already existed and on failure.

Name Type Optional Description
$name string false Name of space

deleteSpace($name)

Delete space.

Returns false if space was deleted, false otherwise.

Name Type Optional Description
$name string true Name of space

listSpaces($names = false)

Get list of spaces.

Returns array of available spaces.

Name Type Optional Description
$names bool true Return names only

spaceExists($space)

Check if space exists.

Returns true if space exists, false otherwise.

Name Type Optional Description
$space string false Name of space

list($space, $keys = false, $arguments = [])

Get list of objects.

Returns array of objects, false on failure.

Name Type Optional Description
$space string false Name of space
$keys bool true Return keys only
$arguments array true Additional api arguments

get($space, $key, $arguments = [])

Get object.

Returns object, null if not found or false on failure.

Name Type Optional Description
$space string false Name of space
$key string false Object key
$arguments array true Additional api arguments

exists($space, $key)

Check if object exists.

Returns true if object exists, false otherwise.

Name Type Optional Description
$space string false Name of space
$key string false Object key

getAcl($space, $key)

Get an objects ACL.

Return string or false on failure.

Name Type Optional Description
$space string false Name of space
$key string false Object key

setAcl($space, $key, $acl)

Set an objects ACL.

Returns true or false on failure.

Name Type Optional Description
$space string false Name of space
$key string false Object key
$acl string false ACL value

upload($space, $key, $content, $public = false, $arguments = [])

Upload content.

Return key as string if successful or false on failure.

Name Type Optional Description
$space string false Name of space
$key string false Object key
$content string
resource
Psr\Http\Message\StreamInterface
false Content to add
$public bool true Object is public
$arguments array true Additional api arguments

uploadFile($space, $key, $file, $public = false, $arguments = [])

Upload file.

Return key as string if successful or false on failure.

Name Type Optional Description
$space string false Name of space
$key string false Object key
$file string false File path on disk
$public bool true Object is public
$arguments array true Additional api arguments

multipartUploadFile($space, $key, $file, $public = false, $arguments = [])

Multipart file upload.

Return key as string if successful or false on failure.

Name Type Optional Description
$space string false Name of space
$key string false Object key
$file string false File path on disk
$public bool true Object is public
$arguments array true Additional api arguments

download($space, $key, $destination)

Downloads a file locally.

Returns true if file downloaded successfully or false on failure.

Name Type Optional Description
$space string false Name of space
$key string false Object key
$destination string false File destination

publicUrl($space, $key)

Get object public URL.

Returns a URL string.

Name Type Optional Description
$space string false Name of space
$key string false Object key

presignedDownload($space, $key, $duration = '+5 minutes')

Generate a presigned download URL.

Returns presigned download URL as a string.

Name Type Optional Description
$space string false Name of space
$key string false Object key
$duration string true Length of time URL is valid, eg. '+5 minutes'

presignedUpload($space, $key, $duration = '+5 minutes')

Generate a presigned upload URL.

Returns presigned upload URL as a string.

Name Type Optional Description
$space string false Name of space
$key string false Object key
$duration string true Length of time URL is valid, eg. '+5 minutes'

delete($space, $key)

Delete object.

Returns true on success, false on failure.

Name Type Optional Description
$space string false Name of space
$key string false Object key

baseKey($key)

Get base key. Similar to PHP dirname().

Returns string.

Name Type Optional Description
$key string false Object key

verifyRequest(&$request, $key, $default = [])

Verify HTTP result has particular property.

Name Type Optional Description
&$request object false Api result
$key string false Value key
$default mixed true Default value

createAuthorizationSignature($arguments)

Create an authorization signature header.

Returns an array. First item being an array of headers use for api authorization, second item is the headers compiled to a string.

Name Type Optional Description
$arguments array false Arguments required to construct signature

getClient()

Get S3Client instance.

Returns S3Client.

static createClient($key, $secret, $endpoint)

Create S3Client.

Returns S3Client instance.

Name Type Optional Description
$key string false Spaces api key
$secret string false Spaces api secret
$endpoint string false Api endpoint

static create($key, $secret, $endpoint)

Create Spaces Client.

Returns Client instance.

Name Type Optional Description
$key string false Spaces api key
$secret string false Spaces api secret
$region string false Spaces region, eg. nyc1

BAG\Spaces\Space

Space class that can be used to manage a single space and its objects.

Constants

  • ACL_PUBLIC = 'public-read'
  • ACL_PRIVATE = 'private'

construct($space, $key, $secret, $region, $create = false)

Name Type Optional Description
$space string false Name of space
$key string false Spaces api key
$secret string false Spaces api secret
$region string false Spaces region, eg. nyc1
$create string true Create space if non-existent

list($keys = false, $arguments = [])

Get list of objects.

Returns array of objects, false on failure.

Name Type Optional Description
$keys bool true Return keys only
$arguments array true Additional api arguments

get($key, $arguments = [])

Get object.

Returns object, null if not found or false on failure.

Name Type Optional Description
$key string false Object key
$arguments array true Additional api arguments

exists($key)

Check if object exists.

Returns true if object exists, false otherwise.

Name Type Optional Description
$key string false Object key

getAcl($key)

Get an objects ACL.

Return string or false on failure.

Name Type Optional Description
$key string false Object key

setAcl($key, $acl)

Set an objects ACL.

Returns true or false on failure.

Name Type Optional Description
$key string false Object key
$acl string false ACL value

upload($key, $content, $public = false, $arguments = [])

Upload content.

Return key as string if successful or false on failure.

Name Type Optional Description
$key string false Object key
$content string
resource
Psr\Http\Message\StreamInterface
false Content to add
$public bool true Object is public
$arguments array true Additional api arguments

uploadFile($key, $file, $public = false, $arguments = [])

Upload file.

Return key as string if successful or false on failure.

Name Type Optional Description
$key string false Object key
$file string false File path on disk
$public bool true Object is public
$arguments array true Additional api arguments

multipartUploadFile($key, $file, $public = false, $arguments = [])

Multipart file upload.

Return key as string if successful or false on failure.

Name Type Optional Description
$key string false Object key
$file string false File path on disk
$public bool true Object is public
$arguments array true Additional api arguments

download($key, $destination)

Downloads a file locally.

Returns true if file downloaded successfully or false on failure.

Name Type Optional Description
$key string false Object key
$destination string false File destination

publicUrl($key)

Get object public URL.

Returns a URL string.

Name Type Optional Description
$key string false Object key

presignedDownload($key, $duration = '+5 minutes')

Generate a presigned download URL.

Returns presigned download URL as a string.

Name Type Optional Description
$key string false Object key
$duration string true Length of time URL is valid, eg. '+5 minutes'

presignedUpload($key, $duration = '+5 minutes')

Generate a presigned upload URL.

Returns presigned upload URL as a string.

Name Type Optional Description
$key string false Object key
$duration string true Length of time URL is valid, eg. '+5 minutes'

delete($key)

Delete object.

Returns true on success, false on failure.

Name Type Optional Description
$key string false Object key

baseKey(string $key)

Get base key. Similar to PHP dirname().

Returns string.

Name Type Optional Description
$key string false Object key

getClient()

Get Client instance.

Returns Client.

BAG\Spaces\Authorization

Class that assists with generating http authorization headers.

construct($key, $secret)

Name Type Optional Description
$key string false Spaces api key
$secret string false Spaces api secret

create($arguments)

Create authorization headers and return full set of headers generated.

Returns an array. First item being an array of headers use for api authorization, second item is the headers compiled to a string.

Name Type Optional Description
$arguments array false Request arguments

bag/digitalocean-spaces-helpers 适用场景与选型建议

bag/digitalocean-spaces-helpers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 07 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「storage」 「s3」 「object」 「aws」 「digitalocean」 「spaces」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 bag/digitalocean-spaces-helpers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bag/digitalocean-spaces-helpers 我们能提供哪些服务?
定制开发 / 二次开发

基于 bag/digitalocean-spaces-helpers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 34
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-25