rossriley/doctrine-uploader
Small package to handle file uploads via a save to a Flysystem Handler
Maintainers
1.0
2015-10-29 15:31 UTC
Requires
- doctrine/orm: ^2.5
- league/flysystem: ^0.4
- siriusphp/upload: ^1.2
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
MIT ed079ea40bdf8b58b19b09d76344a660c2c8f509
- Ross Riley <riley.ross.woop@gmail.com>
This package is not auto-updated.
Last update: 2026-06-21 01:18:55 UTC
README
Doctrine Uploader
This is a very basic composer package designed to slot into an existing Doctrine ORM based project.
The listener takes care of handling file uploads and saves the resulting path to the Entity.
How to bootstrap
Define your entity targets.
This is an array in the format Entity\Class=>[field1,field2] for example.
$targets = [
'Myproject\Entity\User' => ['logo','profilepic'],
'Myproject\Entity\Company' => ['logo']
];
Provide a filesystem handler
This project uses Flysystem(http://flysystem.thephpleague.com) to handle saves. The simplest usage is as follows.
$fsAdapter = new League\Flysystem\Adapter\Local('/path/to/save');
$filesystem = new League\Flysystem\Filesystem($fsAdapter);
$handler = Handler($filesystem);
Add the listener to your EntityManager setup with the above setup
use Doctrine\Uploader\Listener;
$em->getEventManager()->addEventListener([Doctrine\ORM\Events::preUpdate], new Listener($handler, $targets));
Putting it all together.
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use Doctrine\Uploader\Listener;
use Doctrine\Uploader\Handler;
$targets = [
'Myproject\Entity\User' => ['logo','profilepic'],
'Myproject\Entity\Company' => ['logo']
];
$fsAdapter = new Local('/path/to/save');
$filesystem = new Filesystem($fsAdapter);
$handler = Handler($filesystem);
$em->getEventManager()->addEventListener([Doctrine\ORM\Events::preUpdate], new Listener($handler, $targets));
