Installation
composer require arxy/files
Basic Configuration
Add to config/packages/arxy_files.yaml:
arxy_files:
managers:
default:
driver: orm
class: 'App\Entity\File'
storage: 'public'
naming_strategy: 'Arxy\FilesBundle\NamingStrategy\SplitHashStrategy'
repository: 'App\Repository\FileRepository'
Create File Entity
Extend \Arxy\FilesBundle\Entity\File:
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Arxy\FilesBundle\Entity\File as BaseFile;
#[ORM\Entity]
class File extends BaseFile { ... }
First Upload
use Arxy\FilesBundle\ManagerInterface;
public function uploadFile(Request $request, ManagerInterface $manager)
{
$file = $request->files->get('file');
$fileEntity = $manager->upload($file);
// Persist via Doctrine orm
}
File Upload & Persistence
ManagerInterface for uploads:
$manager->upload($splFileInfo); // Returns File entity
postPersist/preRemove.Embedded Files
EmbeddableFile for lightweight file references:
#[ORM\Embedded(class: EmbeddableFile::class)]
private ?EmbeddableFile $thumbnail;
Form Integration
FileType for Symfony forms:
$builder->add('document', FileType::class, [
'input_options' => ['attr' => ['accept' => 'application/pdf']]
]);
File Serving
return $downloadUtility->createResponse($fileEntity);
$pathResolver->getPath($fileEntity); // Returns filesystem path
Custom Naming Strategies
AppendExtensionStrategy):
$naming = new AppendExtensionStrategy(new SplitHashStrategy());
LiipImagine Integration
FileFilterPathResolver for dynamic image paths:
$resolver->getUrl(new FileFilter($file, 'thumbnail'));
Event-Driven Workflows
DoctrineORMListener for custom logic:
$listener = new CustomFileListener($manager);
// Register with Doctrine
Double Uploads
md5Hash for deduplication. Files with identical hashes reuse storage.File Persistence Timing
postPersist listeners.Naming Strategy Conflicts
SplitHashStrategy first.Doctrine ORM Only
RepositoryInterface.Check File Paths
namingStrategy->getPath($file) to verify structure.Verify Storage Adapter
Local, S3) are configured correctly.Listener Registration
DoctrineORMListener is tagged in services:
tags:
- { name: doctrine.event_listener, event: postPersist }
Custom Storage Backends
StorageInterface for non-FlySystem storage (e.g., database blobs).Validation Rules
FileType constraints:
$builder->add('file', FileType::class, [
'constraints' => [new File\MaxSize('10M')]
]);
Path Normalization
PathResolver for custom URL schemes (e.g., CDN prefixes).default manager in arxy_files.yaml.flysystem config matches the manager’s storage key.EmbeddableFile for lightweight references (avoids full entity overhead).How can I help you explore Laravel packages today?