-
Notifications
You must be signed in to change notification settings - Fork 823
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c523022
commit 6e464dc
Showing
6 changed files
with
97 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
use SilverStripe\ORM\FieldType\DBVarchar; | ||
use SilverStripe\Validation\EmailValidator; | ||
|
||
class DBEmail extends DBVarchar | ||
{ | ||
protected string $fieldValidatorClass = EmailValidator::class; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Validation; | ||
|
||
use SilverStripe\Core\Validation\ValidationResult; | ||
use SilverStripe\Validation\FieldValidator; | ||
|
||
class EmailValidator extends FieldValidator | ||
{ | ||
protected function validateValue(ValidationResult $result): ValidationResult | ||
{ | ||
// Replace this with symfony constraint email validation | ||
if (!filter_var($this->value, FILTER_VALIDATE_EMAIL)) { | ||
$message = _t('SilverStripe\\Forms\\EmailField.VALIDATION', 'Please enter an email address'); | ||
$result->addFieldError($this->name, $message); | ||
} | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Validation; | ||
|
||
use SilverStripe\Core\Validation\ValidationResult; | ||
|
||
abstract class FieldValidator | ||
{ | ||
protected string $name; | ||
|
||
protected mixed $value; | ||
|
||
public function __construct(string $name, mixed $value) | ||
{ | ||
$this->name = $name; | ||
$this->value = $value; | ||
} | ||
|
||
public function validate(): ValidationResult | ||
{ | ||
$result = ValidationResult::create(); | ||
$result = $this->validateValue($result); | ||
return $result; | ||
} | ||
|
||
abstract protected function validateValue(ValidationResult $result): ValidationResult; | ||
} |