VOOZH about

URL: https://deepwiki.com/hypervel/filesystem/5-extending-and-customization

⇱ Extending and Customization | hypervel/filesystem | DeepWiki


Loading...
Menu

Extending and Customization

This document provides an overview of the extensibility mechanisms available in the Hypervel Filesystem package. The system is designed to support custom drivers, behavior modifications, and flexible configuration to meet diverse storage requirements beyond the built-in drivers.

For detailed instructions on creating custom drivers, see Creating Custom Drivers. For a comprehensive reference of all configuration options, see Configuration Reference.


Overview of Extension Points

The Hypervel Filesystem package provides multiple extension points that allow developers to customize behavior without modifying the core library. These extension points follow standard design patterns to ensure compatibility and maintainability.

Primary Extension Mechanisms

MechanismPurposeImplementation Location
Custom DriversAdd support for new storage backendsFilesystemManager::extend()
Poolable DriversEnable connection pooling for custom driversFilesystemManager::addPoolable()
Temporary URL CallbacksCustomize URL generation logicFilesystemAdapter::buildTemporaryUrlsUsing()
MacrosAdd methods to adapter instancesMacroable trait
ConfigurationCustomize driver behavior and credentialsconfig/autoload/filesystems.php

Sources:


Extension Architecture

The following diagram illustrates how custom extensions integrate with the core system architecture:


Diagram: Extension Registration and Resolution Flow

This diagram shows how extensions are registered via the extend(), macro(), and buildTemporaryUrlsUsing() methods, and how they are resolved at runtime. The FilesystemManager::resolve() method checks for custom creators in the customCreators array and optionally wraps them in a FilesystemPoolProxy if the driver is marked as poolable.

Sources:


Custom Driver Registration

The FilesystemManager class provides the extend() method to register custom filesystem drivers. This method accepts a driver name, a closure that creates the driver instance, and an optional flag to mark the driver as poolable.

Registration Method Signature


The $callback closure receives two parameters:

  1. ContainerInterface $app - The Hyperf DI container
  2. array $config - The configuration array for this disk

Custom Driver Resolution Flow


Diagram: Custom Driver Registration and Resolution Sequence

This sequence diagram shows the two-phase lifecycle of custom drivers: registration via extend() and resolution via disk(). The customCreators array stores the callback, and if the driver is marked as poolable, it is added to the poolables array for automatic pool proxy wrapping.

Sources:


Poolable Drivers

Custom drivers can opt into connection pooling by setting the $poolable parameter to true when calling extend(). This is particularly useful for drivers that maintain persistent connections or expensive client objects.

Poolable Driver Characteristics

The built-in poolable drivers are defined in the $poolables array:

src/FilesystemManager.php61


When a driver is marked as poolable:

  1. The FilesystemManager wraps the driver creator in createPoolProxy()
  2. A FilesystemPoolProxy instance is created with pool configuration
  3. The proxy manages a pool of driver instances using hypervel/object-pool
  4. Pool configuration is read from $config['pool']

Adding Custom Poolable Drivers

The HasPoolProxy trait provides the addPoolable() method:

src/FilesystemManager.php41


To mark an additional driver as poolable after initialization:


For more details on connection pooling behavior, see Object Pooling for Cloud Drivers.

Sources:


Behavior Customization

Beyond custom drivers, the system provides mechanisms to customize behavior of existing drivers.

Temporary URL Customization

The FilesystemAdapter supports custom temporary URL generation logic through the buildTemporaryUrlsUsing() method:

src/FilesystemAdapter.php837-840


The callback receives three parameters:

  • string $path - The file path
  • DateTimeInterface $expiration - The URL expiration time
  • array $options - Additional options

When a custom callback is set, it takes precedence over the adapter's built-in getTemporaryUrl() method:

src/FilesystemAdapter.php661-676

The callback is bound to the adapter instance, allowing access to protected methods and properties.

Macro Extension

The FilesystemAdapter uses the Macroable trait to support dynamic method addition:

src/FilesystemAdapter.php52-55


This allows adding custom methods to all adapter instances:


Macros are particularly useful for adding domain-specific helper methods without subclassing.

Sources:


Configuration Extension

All drivers support configuration-based customization through the config/autoload/filesystems.php file. The configuration array for each disk is passed to the driver creator and stored in the adapter.

Configuration Access in Drivers

Drivers receive configuration through the constructor:

src/FilesystemAdapter.php75-92


The configuration is accessible via:

Common Configuration Patterns

Configuration KeyPurposeExample Value
driverSpecifies which driver to use'local', 's3', 'custom'
rootBase path for operations'/var/storage'
visibilityDefault file visibility'public', 'private'
throwWhether to throw exceptionstrue, false
prefixPath prefix for scoped access'uploads/'
read-onlyEnable read-only modetrue, false
poolConnection pool configuration['min' => 1, 'max' => 10]
urlBase URL for public files'https://cdn.example.com'
temporary_urlTemporary URL configuration['key' => '...']

Sources:


Extensibility Points Map

The following diagram shows all extensibility points and their relationships:


Diagram: Complete Extensibility Points Map

This diagram maps all extension mechanisms available in the system, organized by layer. Driver layer extensions affect which driver is instantiated, adapter layer extensions modify behavior of adapter instances, Flysystem layer extensions wrap the underlying adapter, pool layer extensions control connection pooling, and configuration extensions customize all aspects.

Sources:


Integration Patterns

Service Provider Pattern

Custom drivers are typically registered in a service provider or bootstrap file:


Conditional Extensions

Extensions can be registered conditionally based on environment or configuration:


Sources:


Next Steps

Sources: