class UserNameConstraintValidator in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/user/src/Plugin/Validation/Constraint/UserNameConstraintValidator.php \Drupal\user\Plugin\Validation\Constraint\UserNameConstraintValidator
Validates the UserName constraint.
Hierarchy
- class \Symfony\Component\Validator\ConstraintValidator implements ConstraintValidatorInterface
- class \Drupal\user\Plugin\Validation\Constraint\UserNameConstraintValidator
Expanded class hierarchy of UserNameConstraintValidator
File
- core/
modules/ user/ src/ Plugin/ Validation/ Constraint/ UserNameConstraintValidator.php, line 17 - Contains \Drupal\user\Plugin\Validation\Constraint\UserNameConstraintValidator.
Namespace
Drupal\user\Plugin\Validation\ConstraintView source
class UserNameConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($items, Constraint $constraint) {
if (!isset($items) || !$items->value) {
$this->context
->addViolation($constraint->emptyMessage);
return;
}
$name = $items
->first()->value;
if (substr($name, 0, 1) == ' ') {
$this->context
->addViolation($constraint->spaceBeginMessage);
}
if (substr($name, -1) == ' ') {
$this->context
->addViolation($constraint->spaceEndMessage);
}
if (strpos($name, ' ') !== FALSE) {
$this->context
->addViolation($constraint->multipleSpacesMessage);
}
if (preg_match('/[^\\x{80}-\\x{F7} a-z0-9@_.\'-]/i', $name) || preg_match('/[\\x{80}-\\x{A0}' . '\\x{AD}' . '\\x{2000}-\\x{200F}' . '\\x{2028}-\\x{202F}' . '\\x{205F}-\\x{206F}' . '\\x{FEFF}' . '\\x{FF01}-\\x{FF60}' . '\\x{FFF9}-\\x{FFFD}' . '\\x{0}-\\x{1F}]/u', $name)) {
$this->context
->addViolation($constraint->illegalMessage);
}
if (Unicode::strlen($name) > USERNAME_MAX_LENGTH) {
$this->context
->addViolation($constraint->tooLongMessage, array(
'%name' => $name,
'%max' => USERNAME_MAX_LENGTH,
));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConstraintValidator:: |
protected | property | 3 | |
ConstraintValidator:: |
protected | function | Wrapper for {@link ExecutionContextInterface::buildViolation} that supports the 2.4 context API. | |
ConstraintValidator:: |
protected | function | Wrapper for {@link ExecutionContextInterface::buildViolation} that supports the 2.4 context API. | |
ConstraintValidator:: |
protected | function | Returns a string representation of the type of the value. | |
ConstraintValidator:: |
protected | function | Returns a string representation of the value. | |
ConstraintValidator:: |
protected | function | Returns a string representation of a list of values. | |
ConstraintValidator:: |
public | function |
Initializes the constraint validator. Overrides ConstraintValidatorInterface:: |
1 |
ConstraintValidator:: |
constant | Whether to cast objects with a "__toString()" method to strings. | ||
ConstraintValidator:: |
constant | Whether to format {@link \DateTime} objects as RFC-3339 dates ("Y-m-d H:i:s"). | ||
UserNameConstraintValidator:: |
public | function |
Checks if the passed value is valid. Overrides ConstraintValidatorInterface:: |