UploadedFileRepository.php 3.57 KiB
<?php
/*
 * Copyright (C) 2015 IRSTEA
 * All rights reserved.
 */
namespace Irstea\FileUploadBundle\Entity\Repository;
use Doctrine\ORM\EntityRepository;
use Gaufrette\Filesystem;
use Irstea\FileUploadBundle\Entity\UploadedFile;
use Irstea\FileUploadBundle\Event\FileUploadCompleteEvent;
use Irstea\FileUploadBundle\Exception\RejectedFileException;
use Irstea\FileUploadBundle\FileUploadEvents;
use Irstea\FileUploadBundle\Model\FileManagerInterface;
use Irstea\FileUploadBundle\Model\UploadedFileInterface;
use Psr\Log\LogLevel;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
 * Description of UploadedFileRepository
 * @author Guillaume Perréal <guillaume.perreal@irstea.fr>
class UploadedFileRepository extends EntityRepository implements FileManagerInterface
    use \Psr\Log\LoggerAwareTrait;
    /**
     * @var Filesystem
    protected $filesystem;
    /**
     * @var EventDispatcher
    protected $eventDispatcher;
    /**
     * @param Filesystem $filesystem
    public function setFilesystem(Filesystem $filesystem)
        $this->filesystem = $filesystem;
    /**
     * @param EventDispatcherInterface $eventDispatcher
    public function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
        $this->eventDispatcher = $eventDispatcher;
    public function create($filename, $size, $mimeType, $lastModified)
        $file = new UploadedFile();
        $file
            ->setFilesystem($this->filesystem)
            ->setDisplayName($filename)
            ->setMetadata(
                    'original' => [
                        'filename'     => $filename,
                        'size'         => $size,