Total Complexity | 4 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class ExtensionConstraint implements ConstraintInterface |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $errorMessageTemplate = 'File extension {extension} is invalid'; |
||
13 | |||
14 | /** |
||
15 | * allowed extensions |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $allowedExtensions = []; |
||
19 | |||
20 | public function __construct(array $allowedExtensions) |
||
21 | { |
||
22 | $this->allowedExtensions = array_map('strtolower', $allowedExtensions); |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | public function validate(UploadedFile $file): bool |
||
29 | { |
||
30 | return in_array(strtolower($file->getClientOriginalExtension()), $this->allowedExtensions, true); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | public function getErrorMessage(UploadedFile $file): string |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | public function setErrorMessage(string $messageTemplate): void |
||
47 | } |
||
48 | } |
||
49 |