VOOZH about

URL: https://deepwiki.com/hypervel/filesystem

⇱ hypervel/filesystem | DeepWiki


Loading...
Menu

Overview

This document provides an overview of the Hypervel Filesystem package, a unified storage abstraction layer for the Hyperf framework. It introduces the package's purpose, key features, main components, and integration points.

For detailed configuration and setup instructions, see Installation and Configuration. For in-depth architectural details, see Architecture. For driver-specific documentation, see Filesystem Drivers.

Sources: composer.json1-63


Purpose and Scope

The hypervel/filesystem package provides a unified, driver-based abstraction layer for interacting with various storage backends including local filesystems, cloud storage (AWS S3, Google Cloud Storage), and remote protocols (FTP, SFTP). Built on top of League Flysystem, the package extends the base functionality with Hyperf-specific optimizations, including connection pooling for cloud drivers, file locking mechanisms, and HTTP response integration.

The package is designed for applications running on the Hyperf framework with Swoole, where long-lived processes require efficient connection management and coroutine-safe operations. It abstracts storage operations behind consistent interfaces, allowing applications to switch storage backends without code changes.

Sources: composer.json1-11 composer.json31-50


Key Features

The Hypervel Filesystem package provides the following capabilities:

Feature CategoryCapabilitiesAvailable Drivers
Basic OperationsRead, write, delete, copy, move files and directoriesAll drivers
StreamingRead/write streams for memory-efficient large file handlingLocal, S3, GCS
URL GenerationPublic URLs, temporary signed URLs, temporary upload URLsLocal, S3, GCS
Connection PoolingObject pooling for high-concurrency environmentsS3, GCS
File LockingShared and exclusive locks for atomic operationsLocal
HTTP IntegrationDirect HTTP responses, downloads, range requestsLocal, S3, GCS
Path ManagementPrefixing, scoped drivers, read-only modesAll drivers (via Flysystem extensions)
MetadataFile size, last modified time, MIME type, visibilityAll drivers

The package requires PHP 8.2+ and integrates deeply with Hyperf's dependency injection container, making filesystem instances available throughout the application via type-hinted constructors or the Factory contract.

Sources: composer.json31-38 composer.json39-50


System Components

The following diagram maps the major system components to their corresponding code entities:


Component Roles

ComponentFileRole
ConfigProvidersrc/ConfigProvider.phpRegisters DI bindings and publishes configuration to Hyperf
FilesystemManagersrc/FilesystemManager.phpCentral orchestrator; creates, caches, and manages driver instances
FilesystemAdaptersrc/FilesystemAdapter.phpBase adapter wrapping Flysystem with additional functionality
FilesystemPoolProxysrc/FilesystemPoolProxy.phpDecorator for cloud drivers providing connection pooling
LocalFilesystemAdaptersrc/LocalFilesystemAdapter.phpLocal disk storage with signed URL support
AwsS3V3Adaptersrc/AwsS3V3Adapter.phpAWS S3 integration with pre-signed URLs
GoogleCloudStorageAdaptersrc/GoogleCloudStorageAdapter.phpGoogle Cloud Storage with signed URL generation
LockableFilesrc/LockableFile.phpFile locking for atomic operations on local storage
Filesystemsrc/Filesystem.phpUtility class with static helpers like ensureDirectoryExists
join_paths()src/Functions.phpGlobal helper function for path manipulation

For detailed information on component architecture, see System Design and Component Interaction. For the factory pattern implementation, see Factory Pattern and FilesystemManager.

Sources: composer.json23-29


Supported Storage Backends

The package supports multiple storage backends through a driver-based architecture. Drivers are loaded on-demand based on configuration, and optional Flysystem adapter packages must be installed separately.

Driver Comparison

DriverConfiguration KeyRequired PackagePooling SupportSigned URLsUse Case
Locallocalleague/flysystemNoYes (with route)Development, self-hosted
AWS S3s3league/flysystem-aws-s3-v3YesYesProduction cloud storage
Google Cloud Storagegcsleague/flysystem-google-cloud-storageYesYesGoogle Cloud Platform apps
FTPftpleague/flysystem-ftpNoNoLegacy systems
SFTPsftpleague/flysystem-sftp-v3NoNoSecure remote servers
Scopedscopedleague/flysystem-path-prefixingInheritedInheritedPath isolation
Read-OnlyN/A (modifier)league/flysystem-read-onlyInheritedInheritedImmutable storage

Driver Selection Guide


For driver-specific configuration, see Local Filesystem Driver, AWS S3 Driver, and Google Cloud Storage Driver. For pooling details, see Object Pooling for Cloud Drivers.

Sources: composer.json39-50


Integration with Hyperf Framework

The package integrates with Hyperf through the dependency injection container. The ConfigProvider class registers bindings during application bootstrap, making filesystem instances available throughout the application.


Dependency Injection Usage

Applications access filesystem functionality through three primary contracts:




The FilesystemManager is registered as a singleton (src/ConfigProvider.php) to ensure consistent state across the application. Driver instances are cached within the manager to avoid redundant initialization.

For contract details, see Contracts and Interfaces. For configuration specifics, see Installation and Configuration.

Sources: composer.json55-58


Architecture Overview

The package follows a layered architecture with clear separation between framework integration, driver management, and storage implementations.


Architectural Principles

PrincipleImplementationBenefit
Contract-Based DesignFactory, Filesystem, and Cloud interfaces define public APIsPolymorphic driver usage; easy mocking for tests
Adapter PatternFilesystemAdapter wraps Flysystem's FilesystemOperatorConsistent API across drivers; extensibility
Decorator PatternFilesystemPoolProxy wraps cloud adaptersConnection pooling without modifying driver code
Factory PatternFilesystemManager creates and caches driver instancesCentralized configuration; lazy initialization
Dependency InjectionAll components registered in Hyperf DI containerTestability; loose coupling
Modular DependenciesCore package is lightweight; drivers installed separatelyReduced deployment size; pay-for-what-you-use

Design Rationale

The package uses League Flysystem as its foundation to leverage battle-tested storage abstractions. The FilesystemAdapter base class (src/FilesystemAdapter.php) wraps Flysystem's FilesystemOperator and adds Hyperf-specific functionality like HTTP response generation, Macroable trait support, and enhanced error handling.

For cloud drivers (S3 and GCS), the FilesystemPoolProxy (src/FilesystemPoolProxy.php) provides connection pooling via the hypervel/object-pool library. This is critical in Swoole/Hyperf environments where a single process handles many concurrent requests. Without pooling, each request would create new SDK client instances, leading to connection overhead and resource exhaustion.

The FilesystemManager (src/FilesystemManager.php) serves as the central orchestrator, implementing the Factory contract. It resolves driver configurations from config/autoload/filesystems.php, creates driver instances using registered creator callbacks, and caches instances to avoid redundant initialization. The manager also supports custom driver registration via the extend() method, allowing applications to add proprietary storage backends.

For detailed architecture documentation, see System Design and Component Interaction. For extension points, see Creating Custom Drivers.

Sources: composer.json31-50


Getting Started

To begin using the Hypervel Filesystem package:

  1. Install the package via Composer along with desired driver packages (see Installation and Configuration)
  2. Publish the configuration to config/autoload/filesystems.php
  3. Configure storage drivers with credentials and options (see Configuration Reference)
  4. Inject contracts (Factory, Filesystem, or Cloud) into application code
  5. Perform operations using the unified API across all drivers

For conceptual understanding of disks, drivers, and the factory pattern, see Core Concepts. For driver selection guidance, refer to the Supported Storage Backends section above.

Sources: composer.json1-63