1 | <?php |
||
17 | abstract class AbstractFile |
||
18 | { |
||
19 | /** |
||
20 | * @var string |
||
21 | * @ORM\Column(type="string", length=255, nullable=true) |
||
22 | */ |
||
23 | protected $fileName = null; |
||
24 | |||
25 | /** |
||
26 | * @var UploadedFile |
||
27 | */ |
||
28 | protected $file; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $oldFileName; |
||
34 | |||
35 | /** |
||
36 | * @param string $fileName |
||
37 | */ |
||
38 | protected function __construct($fileName) |
||
42 | |||
43 | /** |
||
44 | * @return string |
||
45 | */ |
||
46 | public function getFileName() |
||
50 | |||
51 | /** |
||
52 | * @return string|null |
||
53 | */ |
||
54 | public function getAbsolutePath() |
||
58 | |||
59 | /** |
||
60 | * @return string |
||
61 | */ |
||
62 | public function getWebPath() |
||
71 | |||
72 | /** |
||
73 | * @return string |
||
74 | */ |
||
75 | protected function getUploadRootDir() |
||
80 | |||
81 | /** |
||
82 | * @return string |
||
83 | */ |
||
84 | protected function getTrimmedUploadDir() |
||
88 | |||
89 | /** |
||
90 | * The dir in the web folder where the file needs to be uploaded. |
||
91 | * The base directory is always the src/Frontend/Files/ directory |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | abstract protected function getUploadDir(); |
||
96 | |||
97 | /** |
||
98 | * Sets file. |
||
99 | * |
||
100 | * @param UploadedFile $file |
||
101 | * |
||
102 | * @return static |
||
103 | */ |
||
104 | public function setFile(UploadedFile $file = null) |
||
122 | |||
123 | /** |
||
124 | * @param UploadedFile|null $uploadedFile |
||
125 | * |
||
126 | * @return static |
||
127 | */ |
||
128 | public static function fromUploadedFile(UploadedFile $uploadedFile = null) |
||
135 | |||
136 | /** |
||
137 | * Get file. |
||
138 | * |
||
139 | * @return UploadedFile |
||
140 | */ |
||
141 | public function getFile() |
||
145 | |||
146 | /** |
||
147 | * This function should be called for the life cycle events @ORM\PrePersist() and @ORM\PreUpdate() |
||
148 | */ |
||
149 | public function prepareToUpload() |
||
159 | |||
160 | /** |
||
161 | * This function should be called for the life cycle events @ORM\PostPersist() and @ORM\PostUpdate() |
||
162 | */ |
||
163 | public function upload() |
||
184 | |||
185 | /** |
||
186 | * if there is an error when moving the file, an exception will |
||
187 | * be automatically thrown by move(). This will properly prevent |
||
188 | * the entity from being persisted to the database on error |
||
189 | */ |
||
190 | protected function writeFileToDisk() |
||
194 | |||
195 | /** |
||
196 | * This function should be called for the life cycle event @ORM\PostRemove() |
||
197 | */ |
||
198 | public function remove() |
||
207 | |||
208 | /** |
||
209 | * Returns a string representation of the image. |
||
210 | * |
||
211 | * @return string |
||
212 | */ |
||
213 | public function __toString() |
||
217 | |||
218 | /** |
||
219 | * @param string $fileName |
||
220 | * |
||
221 | * @return static |
||
222 | */ |
||
223 | public static function fromString($fileName) |
||
227 | |||
228 | /** |
||
229 | * {@inheritdoc} |
||
230 | */ |
||
231 | public function jsonSerialize() |
||
235 | |||
236 | public function markForDeletion() |
||
241 | } |
||
242 |