1 | <?php |
||
14 | trait ImageTrait |
||
15 | { |
||
16 | /** |
||
17 | * @var string |
||
18 | * |
||
19 | * @ORM\Column(type="text", nullable=true) |
||
20 | */ |
||
21 | protected $image; |
||
22 | |||
23 | /** |
||
24 | * @Vich\UploadableField(mapping="smart_content_image", fileNameProperty="image") |
||
25 | * |
||
26 | * @Assert\Image |
||
27 | * @Assert\File(maxSize="500k") |
||
28 | * |
||
29 | * @var File |
||
30 | */ |
||
31 | protected $imageFile; |
||
32 | |||
33 | /** |
||
34 | * @return string |
||
35 | */ |
||
36 | public function getImage() |
||
40 | |||
41 | /** |
||
42 | * @param string $image |
||
43 | * |
||
44 | * @return $this |
||
45 | */ |
||
46 | public function setImage($image) |
||
52 | |||
53 | /** |
||
54 | * @return bool |
||
55 | */ |
||
56 | public function hasImage() |
||
60 | |||
61 | /** |
||
62 | * @return File |
||
63 | */ |
||
64 | public function getImageFile() |
||
68 | |||
69 | /** |
||
70 | * It is required that at least one field changes if you are using Doctrine, |
||
71 | * otherwise the event listeners won't be called and the file is lost |
||
72 | * |
||
73 | * @param File|UploadedFile $file |
||
74 | * |
||
75 | * @return $this |
||
76 | */ |
||
77 | public function setImageFile(File $file = null) |
||
89 | } |
||
90 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: