1 | <?php |
||
16 | class Image extends BaseEntity implements ImageInterface |
||
17 | { |
||
18 | /** |
||
19 | * Image from URL. |
||
20 | * |
||
21 | * @Assert\Url() |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $remote = ''; |
||
26 | |||
27 | /** |
||
28 | * Local image. |
||
29 | * |
||
30 | * @Assert\Image( |
||
31 | * maxSize = "2048k", |
||
32 | * minWidth = 200, |
||
33 | * minHeight = 200, |
||
34 | * mimeTypes = {"image/bmp","image/gif","image/jpeg","image/png"}, |
||
35 | * mimeTypesMessage = "Please upload a valid image file" |
||
36 | * ) |
||
37 | * |
||
38 | * @var UploadedFile|null |
||
39 | */ |
||
40 | protected $local; |
||
41 | |||
42 | /** |
||
43 | * @param string $remote |
||
44 | * |
||
45 | * @return Image |
||
46 | */ |
||
47 | 4 | public function setRemote($remote) |
|
48 | { |
||
49 | 4 | $this->remote = $remote; |
|
50 | |||
51 | 4 | return $this; |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * @return string |
||
56 | */ |
||
57 | 3 | public function getRemote() |
|
58 | { |
||
59 | 3 | return $this->remote; |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * @param UploadedFile $local |
||
64 | * |
||
65 | * @return Image |
||
66 | */ |
||
67 | 3 | public function setLocal(UploadedFile $local) |
|
68 | { |
||
69 | 3 | $this->local = $local; |
|
70 | |||
71 | 3 | return $this; |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * @return UploadedFile |
||
76 | */ |
||
77 | 2 | public function getLocal() |
|
81 | |||
82 | /** |
||
83 | * @param string $filename |
||
84 | */ |
||
85 | 2 | public function setFilename($filename) |
|
86 | { |
||
87 | // it is a filename prefix, not a suffix for the download path |
||
88 | 2 | if (strpos($filename, 'tmp/') !== 0) { |
|
89 | 1 | $filename = 'tmp/'.date('Ymd').'/'.$filename; |
|
90 | } |
||
91 | 2 | parent::setFilename($filename); |
|
92 | 2 | } |
|
93 | |||
94 | /** |
||
95 | * Clear local and remote file. |
||
96 | */ |
||
97 | 1 | public function clear() |
|
102 | |||
103 | /** |
||
104 | * Has remote or local image. |
||
105 | * |
||
106 | * @Assert\True(message = "No selected image") |
||
107 | * |
||
108 | * @return bool |
||
109 | */ |
||
110 | 2 | public function hasImage() |
|
114 | } |
||
115 |