Completed
Push — feature/admin-avatar ( e274c7...a097f4 )
by Loïc
01:42
created

File::getPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of AppName.
5
 *
6
 * (c) Monofony
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace App\Entity\Media;
15
16
use App\Entity\IdentifiableTrait;
17
use Doctrine\ORM\Mapping as ORM;
18
use Sylius\Component\Resource\Model\ResourceInterface;
19
use Sylius\Component\Resource\Model\TimestampableTrait;
20
use Symfony\Component\Serializer\Annotation as Serializer;
21
22
/**
23
 * @ORM\MappedSuperclass
24
 */
25
abstract class File implements ResourceInterface
26
{
27
    use IdentifiableTrait;
28
    use TimestampableTrait;
29
30
    /** @var \SplFileInfo|null */
31
    protected $file;
32
33
    /**
34
     * @var string|null
35
     *
36
     * @ORM\Column(type="string")
37
     *
38
     * @Serializer\Groups({"Default", "Detailed"})
39
     */
40
    protected $path;
41
42
    /**
43
     * @var string|null
44
     *
45
     * @ORM\Column(type="string", nullable=true)
46
     */
47
    protected $type;
48
49
    /**
50
     * @var \DateTimeInterface|null
51
     *
52
     * @ORM\Column(type="datetime")
53
     */
54
    protected $createdAt;
55
56
    /**
57
     * @var \DateTimeInterface|null
58
     *
59
     * @ORM\Column(type="datetime", nullable=true)
60
     */
61
    protected $updatedAt;
62
63
    public function __construct()
64
    {
65
        $this->createdAt = new \DateTime();
66
    }
67
68
    public function getFile(): ?\SplFileInfo
69
    {
70
        return $this->file;
71
    }
72
73
    public function setFile(?\SplFileInfo $file): void
74
    {
75
        $this->file = $file;
76
77
        // VERY IMPORTANT:
78
        // It is required that at least one field changes if you are using Doctrine,
79
        // otherwise the event listeners won't be called and the file is lost
80
        if ($file) {
81
            // if 'updatedAt' is not defined in your entity, use another property
82
            $this->updatedAt = new \DateTime('now');
83
        }
84
    }
85
86
    public function getPath(): ?string
87
    {
88
        return $this->path;
89
    }
90
91
    public function setPath(?string $path): void
92
    {
93
        $this->path = $path;
94
    }
95
96
    public function getType(): ?string
97
    {
98
        return $this->type;
99
    }
100
101
    public function setType(?string $type): void
102
    {
103
        $this->type = $type;
104
    }
105
}
106