kcs/filesystem

Filesystem abstraction library

Installs: 2 526

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/kcs/filesystem

v0.1.1 2024-04-18 07:55 UTC

This package is auto-updated.

Last update: 2026-01-29 14:27:32 UTC


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.