Completed
Pull Request — master (#169)
by Mikołaj
05:25
created

Media::setFile()   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 1
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusCmsPlugin\Entity;
14
15
use Sylius\Component\Resource\Model\ToggleableTrait;
16
use Sylius\Component\Resource\Model\TranslatableTrait;
17
use Sylius\Component\Resource\Model\TranslationInterface;
18
use Symfony\Component\HttpFoundation\File\File;
19
20
class Media implements MediaInterface
21
{
22
    use ToggleableTrait;
23
    use SectionableTrait;
24
    use ProductsAwareTrait;
25
    use TranslatableTrait {
26
        __construct as protected initializeTranslationsCollection;
27
    }
28
29
    /** @var int */
30
    protected $id;
31
32
    /** @var string */
33
    protected $type;
34
35
    /** @var string */
36
    protected $code;
37
38
    /** @var string */
39
    protected $path;
40
41
    /** @var File */
42
    protected $file;
43
44
    /** @var string */
45
    protected $mimeType;
46
47
    /** @var string */
48
    protected $originalPath;
49
50
    public function __construct()
51
    {
52
        $this->initializeTranslationsCollection();
53
        $this->initializeSectionsCollection();
54
        $this->initializeProductsCollection();
55
    }
56
57
    public function getId(): ?int
58
    {
59
        return $this->id;
60
    }
61
62
    public function getType(): ?string
63
    {
64
        return $this->type;
65
    }
66
67
    public function setType(?string $type): void
68
    {
69
        $this->type = $type;
70
    }
71
72
    public function getCode(): ?string
73
    {
74
        return $this->code;
75
    }
76
77
    public function setCode(?string $code): void
78
    {
79
        $this->code = $code;
80
    }
81
82
    public function getPath(): ?string
83
    {
84
        return $this->path;
85
    }
86
87
    public function setPath(?string $path): void
88
    {
89
        $this->path = $path;
90
    }
91
92
    public function getOriginalPath(): ?string
93
    {
94
        return $this->originalPath;
95
    }
96
97
    public function setOriginalPath(?string $originalPath): void
98
    {
99
        $this->originalPath = $originalPath;
100
    }
101
102
    public function getFile(): ?File
103
    {
104
        if (null === $this->type && null !== $this->path) {
105
            $this->file = new File($this->path);
106
        }
107
108
        return $this->file;
109
    }
110
111
    public function setFile(?File $file): void
112
    {
113
        $this->file = $file;
114
    }
115
116
    public function hasFile(): bool
117
    {
118
        return null !== $this->file;
119
    }
120
121
    public function getMimeType(): ?string
122
    {
123
        return $this->mimeType;
124
    }
125
126
    public function setMimeType(?string $mimeType): void
127
    {
128
        $this->mimeType = $mimeType;
129
    }
130
131
    public function getName(): ?string
132
    {
133
        return $this->getMediaTranslation()->getName();
134
    }
135
136
    public function setName(?string $name): void
137
    {
138
        $this->getMediaTranslation()->setName($name);
139
    }
140
141
    public function getDescription(): ?string
142
    {
143
        return $this->getMediaTranslation()->getDescription();
144
    }
145
146
    public function setDescription(?string $description): void
147
    {
148
        $this->getMediaTranslation()->setDescription($description);
149
    }
150
151
    public function getAlt(): ?string
152
    {
153
        return $this->getMediaTranslation()->getAlt();
154
    }
155
156
    public function setAlt(?string $alt): void
157
    {
158
        $this->getMediaTranslation()->setAlt($alt);
159
    }
160
161
    /**
162
     * @return MediaTranslationInterface|TranslationInterface
163
     */
164
    protected function getMediaTranslation(): TranslationInterface
165
    {
166
        return $this->getTranslation();
167
    }
168
169
    protected function createTranslation(): MediaTranslationInterface
170
    {
171
        return new MediaTranslation();
172
    }
173
}
174