-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmailFormatValidator.php
More file actions
52 lines (43 loc) · 1.29 KB
/
Copy pathEmailFormatValidator.php
File metadata and controls
52 lines (43 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace Fab\Formule\Validator;
/*
* This file is part of the Fab/Formule project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* Class EmailFormatValidator
*/
class EmailFormatValidator extends AbstractValidator
{
/**
* @param array $values
* @return array
*/
public function validate(array $values): array
{
$messages = [];
if (filter_var($values['email'], FILTER_VALIDATE_EMAIL) === false) {
$value = LocalizationUtility::translate('error.email.format', 'formule');
$messages['email'] = $value;
}
return $messages;
}
/**
* Validation method expected by Extbase/Formule framework
*
* @param mixed $value
* @return bool
*/
public function isValid($value): bool
{
// For compatibility with Extbase validator interface
// Convert the value to array format expected by validate()
$values = is_array($value) ? $value : ['email' => $value];
$messages = $this->validate($values);
// If there are validation messages, the validation failed
return empty($messages);
}
}