timostamm / orm-resource
Store files in a Doctrine ORM database
v1.1.0
2023-04-17 08:21 UTC
Requires
- php: ^7.2 || ^8.0
- doctrine/orm: ^2.6
- timostamm/web-resource: ^1.1.0
Requires (Dev)
- doctrine/annotations: ^2.0
- mikey179/vfsstream: ^1.6.11
- phpunit/phpunit: ^8.5.23 || ^9
- symfony/cache: >=4.4 < 6
This package is auto-updated.
Last update: 2024-12-17 12:02:22 UTC
README
Doesn't actually store the files in the database, but puts them in a storage directory and references them in the database.
This package uses timostamm/web-resource for file representation.
Files in the file system are never deleted.
Example
/** @ORM\Entity() */ class TestEntity { /** * @ORM\Embedded(class = EmbeddedResource::class ) */ private $file; public function getFile(): ?ResourceInterface { return $this->file; } public function setFile(?ResourceInterface $resource): void { $this->file = EmbeddedResource::create($resource); } } $em->getEventManager() ->addEventSubscriber(new ORMResourceHandler(new HashStorage($storageDir))); $e = new TestEntity(); $e->setFile(Resource::fromFile(__FILE__)); $em->persist($e); $em->flush($e);