UploadedFile.php 12.06 KiB
<?php
/*
 * Copyright (C) 2015 IRSTEA
 * All rights reserved.
 */
namespace Irstea\FileUploadBundle\Entity;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Gaufrette\Filesystem;
use Gaufrette\StreamMode;
use InvalidArgumentException;
use Irstea\FileUploadBundle\Model\UploadedFileInterface;
use Rhumsaa\Uuid\Uuid;
/**
 * @ORM\Entity(repositoryClass="Irstea\FileUploadBundle\Entity\Repository\UploadedFileRepository")
 * @ORM\EntityListeners({"Irstea\FileUploadBundle\Listener\UploadedFileListener"})
class UploadedFile implements UploadedFileInterface
    // Taille de bloc utilisé pour les copies
    static public $copyBlockSize = 8192;
    /**
     * @ORM\Id
     * @ORM\Column(type="guid")
     * @var string
    private $id;
    /**
     * @ORM\Column(type="string", length=1024)
     * @var string
    private $displayName;
    /**
     * @ORM\Column(type="string", length=1024)
     * @var string
    private $path;
    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @var string
    private $mimeType;
    /**
     * @ORM\Column(type="integer", nullable=true)
     * @var int
    private $size;
    /**
     * @ORM\Column(type="string", length=64, nullable=true)
     * @var string
    private $checksum;
    /**
     * @ORM\Column(type="string", length=10)
     * @var string
    private $etat = self::ETAT_EN_COURS;
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
/** * @ORM\Column(type="datetime") * @var DateTime */ private $createdAt; /** * @ORM\Column(type="json_array", nullable=true) * @var array */ private $metadata; /** * @var Filesystem */ private $filesystem; /** * */ public function __construct() { $this->id = Uuid::uuid4()->toString(); $this->path = "orphan/".$this->id; $this->createdAt = new DateTime('now'); } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set originalFilename * * @param string $displayName * @return UploadedFileInterface */ public function setDisplayName($displayName) { $this->displayName = $displayName; return $this; } /** * Get originalFilename * * @return string */ public function getDisplayName() { return $this->displayName; } /** * Get path * * @return string */ public function getPath() { return $this->path; }
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
/** * Set path * * @param string $path * @return UploadedFileInterface */ public function setPath($path) { if(!static::isSafePath($path)) { throw new InvalidArgumentException("Unsafe path: $path"); } $this->path = trim($path, '/'); return $this; } /** Change le chemin d'un fichier sans changer le nom. * * @param string $newDir Nouveau répertoire * @return UploadedFileInterface */ public function moveTo($newDir) { $this->setPath(rtrim($newDir, '/') . '/' . pathinfo($this->path, PATHINFO_FILENAME)); } /** * Set mimeType * * @param string $mimeType * @return UploadedFileInterface */ public function setMimeType($mimeType) { $this->mimeType = $mimeType; return $this; } /** * Get mimeType * * @return string */ public function getMimeType() { return $this->mimeType; } /** * Set size * * @param integer $size * @return UploadedFileInterface */ public function setSize($size) { $this->size = $size; return $this; } /** * Get size * * @return integer */ public function getSize() { return $this->size;