定制 kcs/filesystem 二次开发

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

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

kcs/filesystem

Composer 安装命令:

composer require kcs/filesystem

包简介

Filesystem abstraction library

README 文档

README

Filesystem abstraction library with local, Async S3, and Google Cloud Storage adapters, plus a PHP stream wrapper and Symfony bundle integration.

Installation

composer require kcs/filesystem

Basic usage

Local filesystem

use Kcs\Filesystem\Local\LocalFilesystem;

$fs = new LocalFilesystem('/var/app/storage');
$fs->write('hello.txt', 'Hello!');
$contents = $fs->read('hello.txt')->read(1024);

Async S3

use AsyncAws\S3\S3Client;
use Kcs\Filesystem\AsyncS3\AsyncS3Filesystem;

$client = new S3Client([
    'region' => 'eu-west-1',
    'accessKeyId' => '...',
    'accessKeySecret' => '...',
]);

$fs = new AsyncS3Filesystem('my-bucket', '/', $client);
$fs->write('path/file.txt', 'content');

Google Cloud Storage

use Google\Cloud\Storage\StorageClient;
use Kcs\Filesystem\GCS\GCSFilesystem;

$client = new StorageClient([
    'projectId' => 'my-project',
    'keyFilePath' => '/path/to/credentials.json',
]);

$fs = new GCSFilesystem('my-bucket', '/', $client);
$fs->write('path/file.txt', 'content');

Symfony bundle configuration

# config/packages/filesystem.yaml
filesystem:
  storages:
    local_storage:
      type: local
      stream_wrapper_protocol: localfs
      options:
        path: '%kernel.project_dir%/var/storage'

    s3_storage:
      type: s3
      options:
        bucket: '%env(S3_BUCKET)%'
        region: '%env(S3_REGION)%'
        access_key: '%env(S3_ACCESS_KEY)%'
        secret_key: '%env(S3_SECRET_KEY)%'
        prefix: 'app'

    gcs_storage:
      type: gcs
      options:
        bucket: '%env(GCS_BUCKET)%'
        project_id: '%env(GCS_PROJECT_ID)%'
        key_file_path: '%env(resolve:GCS_KEY_FILE)%'
        prefix: 'app'

GCS options

  • bucket (required)
  • prefix (optional, default /)
  • project_id (optional)
  • key_file_path (optional)
  • api_endpoint (optional)
  • client (optional, service id)

Stream wrapper

Enable a stream_wrapper_protocol to register a PHP stream wrapper for a storage. For example localfs://path/to/file.txt.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-09-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固