File Storage
Doggy's file storage system is built on League Flysystem, supporting local and S3-compatible storage with file upload, image optimization, and URL generation.
Overview
The storage system lives in src/Service/Storage/:
src/Service/Storage/
├── StorageManager.php # Storage manager (adapter selection)
├── FileUploadService.php # File upload service
├── FileUrlGenerator.php # URL generation/caching
├── ImageOptimizerService.php # Image optimization (Imagine)
└── Adapter/
├── StorageAdapterInterface.php
├── LocalStorageAdapter.php
└── S3StorageAdapter.phpRelated entities in src/Entity/Storage/:
| Entity | Description |
|---|---|
File.php | File record |
StorageConfig.php | Storage configuration (adapter type, params, CDN domain) |
UploadSession.php | Upload session |
Storage Backends
| Backend | Adapter | Use Case |
|---|---|---|
| Local | LocalStorageAdapter | Development, small deployments |
| AWS S3 | S3StorageAdapter | Cloud (supports CDN domain) |
Local Storage
php
// Default local storage: public/uploads/
$adapter = new LocalStorageAdapter(
rootPath: '/var/www/public/uploads',
publicUrl: '/uploads'
);S3 Storage
php
// S3-compatible (AWS, MinIO, Alibaba OSS, etc.)
$adapter = new S3StorageAdapter([
'access_key' => '...',
'secret_key' => '...',
'region' => 'us-east-1',
'bucket' => 'doggy-files',
'endpoint' => 'https://oss-cn-hangzhou.aliyuncs.com',
'cdn_domain' => 'https://cdn.example.com',
]);File Upload
FileUploadService provides a complete upload flow:
php
$file = $fileUploadService->upload($uploadedFile, [
'disk' => 'default',
'optimize' => true,
'max_size' => 52428800, // 50MB
]);Upload flow:
FileUploadingEventdispatched (can intercept and modify options)- File safety check (type, size, extension, MIME)
- SHA-256 hash deduplication
- Date-based path generation (
Y/m/uuid.extoruuid.ext) - Upload to adapter
- Create File entity
FileUploadedEventdispatched- Async image compression (
ImageCompressMessage)
Image Optimization
ImageOptimizerService uses the Imagine library:
php
$optimizer->optimize($sourcePath, $targetPath, [
'max_width' => 1920,
'max_height' => 1080,
'quality' => 80,
'format' => 'webp',
]);URL Generation
FileUrlGenerator supports caching and temporary URLs:
php
$url = $urlGenerator->getUrl($file); // Cached
$tempUrl = $urlGenerator->getTemporaryUrl($file, $expiresAt); // Signed URL
$urlGenerator->invalidateUrl($file); // Clear cacheAdmin Interface
Controller: App\Controller\Admin\StorageConfigController
Templates: templates/admin/storage/