1 | <?php |
||
32 | trait FileUploadTrait |
||
33 | { |
||
34 | |||
35 | /** |
||
36 | * The directory with the Magento media files => target directory for images (relative to the root directory). |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $mediaDir; |
||
41 | |||
42 | /** |
||
43 | * The directory with the images that have to be imported (relative to the root directory). |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $imagesFileDir; |
||
48 | |||
49 | /** |
||
50 | * Contains the mappings for the image names that has been uploaded (old => new image name). |
||
51 | * |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $imageMappings = array(); |
||
55 | |||
56 | /** |
||
57 | * The flag whether to copy the images or not. |
||
58 | * |
||
59 | * @var boolean |
||
60 | */ |
||
61 | protected $copyImages = false; |
||
62 | |||
63 | /** |
||
64 | * Set's the flag to copy the images or not. |
||
65 | * |
||
66 | * @param boolean $copyImages The flag |
||
67 | * |
||
68 | * @return void |
||
69 | */ |
||
70 | 1 | public function setCopyImages($copyImages) |
|
74 | |||
75 | /** |
||
76 | * Return's the flag to copy images or not. |
||
77 | * |
||
78 | * @return boolean The flag |
||
79 | */ |
||
80 | 1 | public function hasCopyImages() |
|
84 | |||
85 | /** |
||
86 | * Set's directory with the Magento media files => target directory for images. |
||
87 | * |
||
88 | * @param string $mediaDir The directory with the Magento media files => target directory for images |
||
89 | * |
||
90 | * @return void |
||
91 | */ |
||
92 | 3 | public function setMediaDir($mediaDir) |
|
96 | |||
97 | /** |
||
98 | * Return's the directory with the Magento media files => target directory for images. |
||
99 | * |
||
100 | * @return string The directory with the Magento media files => target directory for images |
||
101 | */ |
||
102 | 3 | public function getMediaDir() |
|
106 | |||
107 | /** |
||
108 | * Set's directory with the images that have to be imported. |
||
109 | * |
||
110 | * @param string $imagesFileDir The directory with the images that have to be imported |
||
111 | * |
||
112 | * @return void |
||
113 | */ |
||
114 | 3 | public function setImagesFileDir($imagesFileDir) |
|
118 | |||
119 | /** |
||
120 | * Return's the directory with the images that have to be imported. |
||
121 | * |
||
122 | * @return string The directory with the images that have to be imported |
||
123 | */ |
||
124 | 3 | public function getImagesFileDir() |
|
128 | |||
129 | /** |
||
130 | * Adds the mapping from the filename => new filename. |
||
131 | * |
||
132 | * @param string $filename The filename |
||
133 | * @param string $newFilename The new filename |
||
134 | * |
||
135 | * @return void |
||
136 | */ |
||
137 | 1 | public function addImageMapping($filename, $newFilename) |
|
141 | |||
142 | /** |
||
143 | * Returns the mapped filename (which is the new filename). |
||
144 | * |
||
145 | * @param string $filename The filename to map |
||
146 | * |
||
147 | * @return string The mapped filename |
||
148 | */ |
||
149 | 1 | public function getImageMapping($filename) |
|
160 | |||
161 | /** |
||
162 | * Returns TRUE, if the passed filename has already been mapped. |
||
163 | * |
||
164 | * @param string $filename The filename to query for |
||
165 | * |
||
166 | * @return boolean TRUE if the filename has already been mapped, else FALSE |
||
167 | */ |
||
168 | public function imageHasBeenMapped($filename) |
||
172 | |||
173 | /** |
||
174 | * Returns TRUE, if the passed filename has NOT been mapped yet. |
||
175 | * |
||
176 | * @param string $filename The filename to query for |
||
177 | * |
||
178 | * @return boolean TRUE if the filename has NOT been mapped yet, else FALSE |
||
179 | */ |
||
180 | 1 | public function imageHasNotBeenMapped($filename) |
|
184 | |||
185 | /** |
||
186 | * Returns the original filename for passed one (which is the new filename). |
||
187 | * |
||
188 | * @param string $newFilename The new filename to return the original one for |
||
189 | * |
||
190 | * @return string The original filename |
||
191 | */ |
||
192 | public function getInversedImageMapping($newFilename) |
||
203 | |||
204 | /** |
||
205 | * Get new file name, if a filename with the same name already exists. |
||
206 | * |
||
207 | * @param string $targetFilename The name of target file |
||
208 | * |
||
209 | * @return string The new filename |
||
210 | */ |
||
211 | 3 | public function getNewFileName($targetFilename) |
|
239 | |||
240 | /** |
||
241 | * Upload's the file with the passed name to the Magento |
||
242 | * media directory. If the file already exists, the will |
||
243 | * be given a new name that will be returned. |
||
244 | * |
||
245 | * @param string $filename The name of the file to be uploaded |
||
246 | * |
||
247 | * @return string The name of the uploaded file |
||
248 | * @throws \Exception Is thrown, if the file with the passed name is not available |
||
249 | */ |
||
250 | 2 | public function uploadFile($filename) |
|
289 | |||
290 | /** |
||
291 | * Delete the file with the passed name. |
||
292 | * |
||
293 | * @param string $filename The name of the file to be deleted |
||
294 | * |
||
295 | * @return boolean TRUE on success, else FALSE |
||
296 | */ |
||
297 | public function deleteFile($filename) |
||
315 | } |
||
316 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.