<?php
namespace App\EventListener;
use App\Entity\ImagesUp;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Oneup\UploaderBundle\Event\PostPersistEvent;
class UploadListener
{
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
public function onUpload(PostPersistEvent $event)
{
$file = $event->getFile();
$object = new ImagesUp();
$object->setNameImagesUp($file->getFilename());
$object->setCreatedAt(new \DateTimeImmutable());
$this->entityManager->persist($object);
$this->entityManager->flush();
}
}