vendor/rollerworks/password-strength-validator/src/Validator/Constraints/PasswordStrength.php line 22

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the RollerworksPasswordStrengthValidator package.
  4.  *
  5.  * (c) Sebastiaan Stok <s.stok@rollerscapes.net>
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Rollerworks\Component\PasswordStrength\Validator\Constraints;
  11. use Attribute;
  12. use Symfony\Component\Validator\Constraint;
  13. /**
  14.  * @Annotation
  15.  * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
  16.  */
  17. #[Attribute(Attribute::TARGET_PROPERTY Attribute::TARGET_METHOD Attribute::IS_REPEATABLE)]
  18. class PasswordStrength extends Constraint
  19. {
  20.     public $tooShortMessage 'Your password must be at least {{length}} characters long.';
  21.     public $message 'password_too_weak';
  22.     public $minLength 6;
  23.     public $minStrength;
  24.     public $unicodeEquality false;
  25.     public function __construct(
  26.         $options null,
  27.         array $groups null,
  28.               $payload null,
  29.         ?int $minStrength null,
  30.         int $minLength null,
  31.         bool $unicodeEquality null,
  32.         string $message null,
  33.         string $tooShortMessage null
  34.     ) {
  35.         $finalOptions = [];
  36.         if (is_array($options)) {
  37.             $finalOptions $options;
  38.         } else {
  39.             $finalOptions['minStrength'] = $options;
  40.         }
  41.         // The minStrength option is required.
  42.         if ($minStrength !== null) {
  43.             $finalOptions['minStrength'] = $minStrength;
  44.         }
  45.         parent::__construct($finalOptions ?? [], $groups$payload);
  46.         $this->minLength $minLength ?? $this->minLength;
  47.         $this->unicodeEquality $unicodeEquality ?? $this->unicodeEquality;
  48.         $this->message $message ?? $this->message;
  49.         $this->tooShortMessage $tooShortMessage ?? $this->tooShortMessage;
  50.     }
  51.     public function getDefaultOption(): string
  52.     {
  53.         return 'minStrength';
  54.     }
  55.     public function getRequiredOptions(): array
  56.     {
  57.         return ['minStrength'];
  58.     }
  59. }