1 | <?php |
||
15 | abstract class AbstractImage implements JsonSerializable |
||
16 | { |
||
17 | const FALLBACK_IMAGE = null; |
||
18 | |||
19 | /** |
||
20 | * @var int |
||
21 | * @ORM\Id |
||
22 | * @ORM\Column(type="integer") |
||
23 | * @ORM\GeneratedValue(strategy="AUTO") |
||
24 | */ |
||
25 | protected $id; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | * @ORM\Column(type="string", length=255, nullable=true) |
||
30 | */ |
||
31 | protected $alt = null; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | * @ORM\Column(type="string", length=255, nullable=true) |
||
36 | */ |
||
37 | protected $path = null; |
||
38 | |||
39 | /** |
||
40 | * @var UploadedFile |
||
41 | * @Assert\File( |
||
42 | * maxSize = "5M", |
||
43 | * mimeTypes = {"image/jpeg", "image/gif", "image/png"}, |
||
44 | * mimeTypesMessage = "file.invalid_mime_type" |
||
45 | * ) |
||
46 | */ |
||
47 | private $file; |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | private $oldPath; |
||
53 | |||
54 | /** |
||
55 | * @var DateTime |
||
56 | * @ORM\Column(type="datetime") |
||
57 | */ |
||
58 | private $updatedAt; |
||
59 | |||
60 | /** |
||
61 | * @return int |
||
62 | */ |
||
63 | public function getId() |
||
67 | |||
68 | /** |
||
69 | * @return string |
||
70 | */ |
||
71 | public function getAlt() |
||
75 | |||
76 | /** |
||
77 | * @return string |
||
78 | */ |
||
79 | public function getPath() |
||
83 | |||
84 | /** |
||
85 | * @param string $alt |
||
86 | * |
||
87 | * @return self |
||
88 | */ |
||
89 | public function setAlt($alt) |
||
95 | |||
96 | /** |
||
97 | * @return null|string |
||
98 | */ |
||
99 | public function getAbsolutePath() |
||
105 | |||
106 | /** |
||
107 | * @return null|string |
||
108 | */ |
||
109 | public function getWebPath() |
||
118 | |||
119 | /** |
||
120 | * @return string |
||
121 | */ |
||
122 | protected function getUploadRootDir() |
||
128 | |||
129 | /** |
||
130 | * the dir in the web folder where the image needs to be uploaded. |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | abstract protected function getUploadDir(); |
||
135 | |||
136 | /** |
||
137 | * Sets file. |
||
138 | * |
||
139 | * @param UploadedFile $file |
||
140 | */ |
||
141 | public function setFile(UploadedFile $file = null) |
||
153 | |||
154 | /** |
||
155 | * Get file. |
||
156 | * |
||
157 | * @return UploadedFile |
||
158 | */ |
||
159 | public function getFile() |
||
163 | |||
164 | /** |
||
165 | * @ORM\PrePersist() |
||
166 | * @ORM\PreUpdate() |
||
167 | */ |
||
168 | public function preUpload() |
||
178 | |||
179 | /** |
||
180 | * @ORM\PostPersist() |
||
181 | * @ORM\PostUpdate() |
||
182 | */ |
||
183 | public function upload() |
||
206 | |||
207 | /** |
||
208 | * @ORM\PostRemove() |
||
209 | */ |
||
210 | public function removeUpload() |
||
217 | |||
218 | /** |
||
219 | * Returns a string representation of the child. |
||
220 | * |
||
221 | * @return string |
||
222 | */ |
||
223 | public function __toString() |
||
227 | |||
228 | /** |
||
229 | * @return null|string |
||
230 | */ |
||
231 | public function getFallbackImage() |
||
235 | |||
236 | /** |
||
237 | * {@inheritdoc} |
||
238 | */ |
||
239 | public function jsonSerialize() |
||
246 | } |
||
247 |