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) |
||
118 | |||
119 | /** |
||
120 | * @param UploadedFile|null $uploadedFile |
||
121 | * |
||
122 | * @return static |
||
123 | */ |
||
124 | public static function fromUploadedFile(UploadedFile $uploadedFile = null) |
||
131 | |||
132 | /** |
||
133 | * Get file. |
||
134 | * |
||
135 | * @return UploadedFile |
||
136 | */ |
||
137 | public function getFile() |
||
141 | |||
142 | /** |
||
143 | * This function should be called for the life cycle events @ORM\PrePersist() and @ORM\PreUpdate() |
||
144 | */ |
||
145 | public function prepareToUpload() |
||
155 | |||
156 | /** |
||
157 | * This function should be called for the life cycle events @ORM\PostPersist() and @ORM\PostUpdate() |
||
158 | */ |
||
159 | public function upload() |
||
180 | |||
181 | /** |
||
182 | * if there is an error when moving the file, an exception will |
||
183 | * be automatically thrown by move(). This will properly prevent |
||
184 | * the entity from being persisted to the database on error |
||
185 | */ |
||
186 | protected function writeFileToDisk() |
||
190 | |||
191 | /** |
||
192 | * This function should be called for the life cycle event @ORM\PostRemove() |
||
193 | */ |
||
194 | public function remove() |
||
203 | |||
204 | /** |
||
205 | * Returns a string representation of the image. |
||
206 | * |
||
207 | * @return string |
||
208 | */ |
||
209 | public function __toString() |
||
213 | |||
214 | /** |
||
215 | * @param string $fileName |
||
216 | * |
||
217 | * @return static |
||
218 | */ |
||
219 | public static function fromString($fileName) |
||
223 | |||
224 | /** |
||
225 | * {@inheritdoc} |
||
226 | */ |
||
227 | public function jsonSerialize() |
||
231 | |||
232 | public function markForDeletion() |
||
237 | } |
||
238 |