1 | <?php |
||
13 | class Uploadable implements Buildable, Delay, Extension |
||
14 | { |
||
15 | const MACRO_METHOD = 'uploadable'; |
||
16 | |||
17 | /** |
||
18 | * @var bool |
||
19 | */ |
||
20 | private $allowOverwrite = false; |
||
21 | |||
22 | /** |
||
23 | * @var bool |
||
24 | */ |
||
25 | private $appendNumber = false; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $path = ''; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $pathMethod = ''; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private $callback = ''; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | private $filenameGenerator = Validator::FILENAME_GENERATOR_NONE; |
||
46 | |||
47 | /** |
||
48 | * @var float |
||
49 | */ |
||
50 | private $maxSize = 0; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | private $allowedTypes = ''; |
||
56 | |||
57 | /** |
||
58 | * @var string |
||
59 | */ |
||
60 | private $disallowedTypes = ''; |
||
61 | |||
62 | /** |
||
63 | * @var ExtensibleClassMetadata |
||
64 | */ |
||
65 | private $classMetadata; |
||
66 | |||
67 | /** |
||
68 | * @param ExtensibleClassMetadata $classMetadata |
||
69 | */ |
||
70 | public function __construct(ExtensibleClassMetadata $classMetadata) |
||
74 | |||
75 | /** |
||
76 | * Enable the Uploadable extension. |
||
77 | * |
||
78 | * @return void |
||
79 | */ |
||
80 | public static function enable() |
||
88 | |||
89 | /** |
||
90 | * If this option is true, it will overwrite a file if it already exists. If you set "false", |
||
91 | * an exception will be thrown. |
||
92 | * |
||
93 | * Default: false |
||
94 | * |
||
95 | * @return Uploadable |
||
96 | */ |
||
97 | public function allowOverwrite() |
||
103 | |||
104 | /** |
||
105 | * If the file already exists and "allowOverwrite" is false, append a number to the filename. |
||
106 | * |
||
107 | * Example: if you're uploading a file named "test.txt", if the file already exists and this option |
||
108 | * is true, the extension will modify the name of the uploaded file to "test-1.txt", where "1" could |
||
109 | * be any number. The extension will check if the file exists until it finds a filename with a number |
||
110 | * as its postfix that is not used. If you use a filename generator and this option is true, it will |
||
111 | * append a number to the filename anyway if a file with the same name already exists. |
||
112 | * |
||
113 | * Default value: false |
||
114 | * |
||
115 | * @return Uploadable |
||
116 | */ |
||
117 | public function appendNumber() |
||
123 | |||
124 | /** |
||
125 | * The path where the files represented by this entity will be moved. Path can be set in other ways: |
||
126 | * From the listener or from a method. |
||
127 | * |
||
128 | * Default: "". |
||
129 | * |
||
130 | * @param string $path |
||
131 | * |
||
132 | * @return Uploadable |
||
133 | */ |
||
134 | public function path($path) |
||
140 | |||
141 | /** |
||
142 | * Similar to "path", this represents the name of a method on the entity that will return the path |
||
143 | * where the files represented by this entity will be moved. This is useful in several cases. For |
||
144 | * example, you can set specific paths for specific entities, or you can get the path from other |
||
145 | * sources (like a framework configuration) instead of hard-coding it in the entity. |
||
146 | * |
||
147 | * As first argument this method takes default path, so you can return a path relative to the default. |
||
148 | * |
||
149 | * Default: "". |
||
150 | * |
||
151 | * @param string $methodName |
||
152 | * |
||
153 | * @return Uploadable |
||
154 | */ |
||
155 | public function pathMethod($methodName) |
||
161 | |||
162 | /** |
||
163 | * Allows you to set a method name. If set, the method will be called after the file is moved. |
||
164 | * |
||
165 | * This method will receive an array with information about the uploaded file, which includes the |
||
166 | * following keys: |
||
167 | * |
||
168 | * <ul> |
||
169 | * <li>fileName: The filename.</li> |
||
170 | * <li>fileExtension: The extension of the file (including the dot). Example: .jpg</li> |
||
171 | * <li>fileWithoutExt: The filename without the extension.</li> |
||
172 | * <li>filePath: The file path. Example: /my/path/filename.jpg</li> |
||
173 | * <li>fileMimeType: The mime-type of the file. Example: text/plain.</li> |
||
174 | * <li>fileSize: Size of the file in bytes. Example: 140000.</li> |
||
175 | * </ul> |
||
176 | * |
||
177 | * Default value: "". |
||
178 | * |
||
179 | * @param string $callback |
||
180 | * |
||
181 | * @return Uploadable |
||
182 | */ |
||
183 | public function callback($callback) |
||
189 | |||
190 | /** |
||
191 | * Normalizes the filename, leaving only alphanumeric characters in the filename, and replacing |
||
192 | * anything else with a "-". |
||
193 | * |
||
194 | * @return Uploadable |
||
195 | */ |
||
196 | public function alphanumericFilename() |
||
202 | |||
203 | /** |
||
204 | * Generates a sha1 filename for the file. |
||
205 | * |
||
206 | * @return Uploadable |
||
207 | */ |
||
208 | public function sha1Filename() |
||
214 | |||
215 | /** |
||
216 | * Set a custom FilenameGenerator class. This class must implement |
||
217 | * `Gedmo\Uploadable\FilenameGenerator\FilenameGeneratorInterface`. |
||
218 | * |
||
219 | * @param string $className |
||
220 | * |
||
221 | * @return Uploadable |
||
222 | */ |
||
223 | public function customFilename($className) |
||
229 | |||
230 | /** |
||
231 | * Set a maximum size for the file, in bytes. If file size exceeds the value set in this |
||
232 | * configuration, `UploadableMaxSizeException` will be thrown. |
||
233 | * |
||
234 | * Default value: 0, meaning that no size validation will occur. |
||
235 | * |
||
236 | * @param float $bytes |
||
237 | * |
||
238 | * @return Uploadable |
||
239 | */ |
||
240 | public function maxSize($bytes) |
||
246 | |||
247 | /** |
||
248 | * Allow only specific types. |
||
249 | * |
||
250 | * @param array|string ...$type can be an array or multiple string parameters |
||
251 | * |
||
252 | * @return Uploadable |
||
253 | */ |
||
254 | public function allow($type) |
||
263 | |||
264 | /** |
||
265 | * Disallow specific types |
||
266 | * |
||
267 | * @param array|string ...$type can be an array or multiple string parameters |
||
268 | * |
||
269 | * @return Uploadable |
||
270 | */ |
||
271 | public function disallow($type) |
||
280 | |||
281 | /** |
||
282 | * Execute the build process |
||
283 | */ |
||
284 | public function build() |
||
292 | |||
293 | /** |
||
294 | * Build the configuration, based on defaults, current extension configuration and accumulated parameters. |
||
295 | * |
||
296 | * @return array |
||
297 | */ |
||
298 | private function getConfiguration() |
||
322 | } |
||
323 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.