digbang / files
File handling library
Installs: 10 581
Dependents: 0
Suggesters: 1
Security: 0
Stars: 0
Watchers: 36
Forks: 1
Open Issues: 0
Requires
- php: ^7.4 || ^8.0.2
- digbang/doctrine-extensions: ^3.1
- intervention/image: ^2.7
- laravel-doctrine/fluent: ^1.2
- laravel-doctrine/orm: ^1.7
- ramsey/uuid: ^4.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.6
- mockery/mockery: ^1.5
- phpunit/phpunit: ^8.5 || ^9.5
README
This library helps with the handling of files and images. The files are stored physically using Laravel's filesystem configuration; and logically into a table in the database.
Usage
Mappings
$builder->manyToOne(File::class, 'propertyName');
$builder->belongsTo(ImageFile::class, 'imagePropertyName');
Image Handling
Each ImageFile has an optional parent image (the original one). This allows to have a tree of curated images attached to the original.
For example:
public function __construct(FileRepository $repository, ImageCurator $curator) { $this->repository = $repository; $this->curator = $curator; } public function curateImage(ImageFile $originalImage): ImageFile { if (! ($curatedImage = $originalImage->getCurated('SOME_IDENTIFICATION_KEY'))) { $originalImage->setContentGetter(function () use ($originalImage) { return $this->repository->getContents($originalImage->getId()); }); $curation = $this->curator ->resize(WIDTH, HEIGHT) ->interlace() ->optimize() //not yet implemented ->buildCuration(); $curatedImage = $originalImage->curate('SOME_IDENTIFICATION_KEY', $curation); $curatedImage->setContentGetter(function () use ($curatedImage) { return $this->repository->getContents($curatedImage->getId()); }); $this->repository->persist($curatedImage); } return $curatedImage; }
The imageCurator can be extended or replaced. Also, you can implement another curator alongside the pre-existing one and use both at the same time.
The only requirement is that the curator should return an array of callbacks that the Curation object can apply to the image.