bnet/bnrepos

懒加载的PHP5库,提供文件系统抽象层的存储库

1.0.10 2017-10-23 09:01 UTC

This package is auto-updated.

Last update: 2024-08-27 23:01:49 UTC


README

BNRepo 是基于 Gaufrette 的 PHP5 库,提供了不同存储库的文件系统抽象。

RepositoryManager 是懒加载的 - 在第一次使用之前没有动作或对象

入门

1. 创建配置文件(本地目录、FTP、SFTP、S3)

# repositories.yml
bnrepo-test:
 - type: local
 - dir: /tmp

2. 导入存储库的配置

  RepositoryManager::importRepositoriesFromYamlFile('repositories.yml');

3. 从 RepositoryManager 获取存储库

  $repo = RepositoryManager::getRepository('bnrepo-test');

4. 读取/写入/下载/上传数据/文件

  $repo->write('test.txt', 'Hello World');
  echo $repo->read('test.txt') // prints Hello World

文档

配置

设置配置文件 repositories.yml

bnrepo-test-local:
  type: local
  dir: /tmp/bnrepo-test
  create: true

bnrepo-test-s3:
  type: s3
  aws_key: AWS_KEY
  aws_secret: AWS_SECRET
  bucket: bnrepo-test
  dir: bnrepo-test
  create: true
  use_old_version: true
  options:
    default_acl: public-read #DEFAULT is only BucketOwner can read, so everyone with the link can read

bnrepo-test-ftp:
  type: ftp
  host: HOST
  username: USERNAME
  password: PASSWORD
  dir: /bnrepo-test
  passive: false

bnrepo-test-sftp:
  type: sftp
  host: HOST
  port: PORT
  dir: /bnrepo-test
  username: USERNAME
  password: PASSWORD

加载配置

  RepositoryManager::importRepositoriesFromYamlFile('repositories.yml');

使用存储库

  $repo = RepositoryManager::getRepository('bnrepo-test');

每个存储库都是一个 \Gaufrette\Filesystem,因此也请查看其 文档

运行测试

测试使用 PHPUnit。

设置供应商库

由于一些文件系统适配器使用供应商库,因此您应该安装供应商库

$ cd BNRepo
$ php composer.phar install

为要测试的存储库实现配置,并删除 -DISABLED 后缀。如果没有配置,整个 AdapterTest 会跳过。

启动测试套件

$ phpunit

它是绿色的吗?