Repository URL to install this package:
|
Version:
6.3.0 ▾
|
<?php
/**
* Created by IntelliJ IDEA.
* User: martino
* Date: 28/04/16
* Time: 20:14
*/
namespace DigitalAscetic\FileBundle\Entity\File;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* Class File
* @package DigitalAscetic\FileBundle\Entity\File
*
* @ORM\Table(name="managed_file")
* @ORM\Entity()
*
*/
#[ORM\Table(name: "managed_file")]
#[ORM\Entity]
class ManagedFile extends AbstractManagedFile
{
const VIEW_DEFAULT = "default";
const VIEW_COMPLETE = "complete";
const ALIAS = "mFile";
public static function getSerializationGroups($viewName): array
{
switch ($viewName) {
case 'complete' :
$result = array('id', 'file_default', 'file_complete');
break;
default:
$result = array('id', 'file_default');
break;
}
return $result;
}
/**
*
* @type {string}
*/
const STORAGE_STANDARD = 'STANDARD';
/**
*
* @type {string}
*/
const STORAGE_REDUCED_REDUNDANCY = 'REDUCED_REDUNDANCY';
/**
*
* @type {string}
*/
const STORAGE_STANDARD_IA = 'STANDARD_IA';
/**
*
* @type {string}
*/
const GLACIER = 'GLACIER';
/**
* @var string|null The name of the media
*
* @ORM\Column(name="name", type="string", length=255, nullable=true)
* @Groups({"file_default"})
*/
#[ORM\Column(name: "name", type: "string", length: 255, nullable: true)]
#[Groups("file_default")]
private ?string $name = null;
/**
* @var string|null The title for the file
*
* @ORM\Column(name="title", type="string", length=255, nullable=true)
* @Groups({"file_default"})
*/
#[ORM\Column(name: "title", type: "string", length: 255, nullable: true)]
#[Groups("file_default")]
private ?string $title = null;
/**
* @var string|null The name of the media
*
* @ORM\Column(name="description", type="text", length=2048, nullable=true)
* @Groups({"file_default"})
*/
#[ORM\Column(name: "description", type: "text", length: 2048, nullable: true)]
#[Groups("file_default")]
private ?string $description = null;
/**
* @var string
*
* @ORM\Column(name="uri", type="string", length=2048)
* @Groups({"file_default"})
*/
#[ORM\Column(name: "uri", type: "string", length: 2048)]
#[Groups("file_default")]
private string $uri;
/**
* @var int|null
*
* @ORM\Column(name="size", type="integer", nullable=true)
* @Groups({"file_default"})
*/
#[ORM\Column(name: "size", type: "integer", nullable: true)]
#[Groups("file_default")]
private ?int $size = null;
/**
* @var string
*
* @ORM\Column(name="mimeType", type="string", length=255, nullable=false)
* @Groups({"file_default"})
*/
#[ORM\Column(name: "mimeType", type: "string", length: 255, nullable: false)]
#[Groups("file_default")]
private string $mimeType;
/**
* @var string
*
* @ORM\Column(name="storageClass", type="string", length=255, nullable=false)
* @Groups({"file_complete"})
*/
#[ORM\Column(name: "storageClass", type: "string", length: 255, nullable: false)]
#[Groups("file_complete")]
private string $storageClass;
/**
* @var bool
*
* @ORM\Column(name="public", type="boolean", nullable=false)
* @Groups({"file_complete"})
*/
#[ORM\Column(name: "public", type: "boolean", nullable: false)]
#[Groups("file_complete")]
private bool $public;
/* File constructor.
*
* @param string $uri
* @param string $mimeType
* @param $size
* @param bool $public
* @param string $storageClass
*/
public function __construct(
string $uri, string $mimeType, $size, bool $public = true,
string $storageClass = ManagedFile::STORAGE_STANDARD)
{
$this->mimeType = $mimeType;
$this->size = $size;
$this->uri = $uri;
$this->public = $public;
$this->storageClass = $storageClass;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @param string|null $description
*/
public function setDescription(?string $description): void
{
$this->description = $description;
}
/**
* @return string
*/
public function getMimeType(): string
{
return $this->mimeType;
}
/**
* @param string $mimeType
*/
public function setMimeType(string $mimeType)
{
$this->mimeType = $mimeType;
}
/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @param string|null $name
*/
public function setName(?string $name): void
{
$this->name = $name;
}
/**
* @return int|null
*/
public function getSize(): ?int
{
return $this->size;
}
/**
* @param int|null $size
*/
public function setSize(?int $size): void
{
$this->size = $size;
}
/**
* @return string
*/
public function getUri(): string
{
return $this->uri;
}
/**
* @param string $uri
*/
public function setUri(string $uri)
{
$this->uri = $uri;
}
/**
* @return bool
*/
public function getPublic(): bool
{
return $this->public;
}
/**
* @param bool $public
*/
public function setPublic(bool $public)
{
$this->public = $public;
}
public function getPathWithoutBucket(): string
{
$path = $this->getPath();
return substr($path, strpos($path, '/', 2));
}
public function getPath(): string
{
$parsedUrl = parse_url($this->uri);
$path = null;
if (isset($parsedUrl['path'])) {
$path = $parsedUrl['path'];
}
return $path;
}
public function setPath(string $newPath)
{
$parsedUrl = parse_url($this->uri);
if (isset($parsedUrl['path'])) {
if (!str_starts_with('/', $newPath)) {
$newPath = '/' . $newPath;
}
$newUri = str_replace($parsedUrl['path'], $newPath, $this->uri);
}
$this->uri = $newUri ?? $this->uri;
}
/**
* @return string
*/
public function getStorageClass(): string
{
return $this->storageClass;
}
/**
* @param string $storageClass
*/
public function setStorageClass(string $storageClass)
{
$this->storageClass = $storageClass;
}
/**
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* @param string|null $title
*/
public function setTitle(?string $title): void
{
$this->title = $title;
}
public function getFileExtension(): string
{
return substr(strrchr($this->name, '.'), 1);
}
/**
* Name used in the __toString method
*
* @return string
*/
public function getInstanceName(): string
{
return $this->uri;
}
}