AbstractComparison.php
1 year ago
AbstractComparisonValidator.php
1 year ago
All.php
1 year ago
AllValidator.php
4 years ago
AtLeastOneOf.php
1 year ago
AtLeastOneOfValidator.php
1 year ago
Bic.php
1 year ago
BicValidator.php
1 year ago
Blank.php
1 year ago
BlankValidator.php
4 years ago
Callback.php
1 year ago
CallbackValidator.php
4 years ago
CardScheme.php
1 year ago
CardSchemeValidator.php
1 year ago
Cascade.php
1 year ago
Choice.php
1 year ago
ChoiceValidator.php
1 year ago
Cidr.php
1 year ago
CidrValidator.php
4 years ago
Collection.php
1 year ago
CollectionValidator.php
4 years ago
Composite.php
1 year ago
Compound.php
4 years ago
CompoundValidator.php
4 years ago
Count.php
1 year ago
CountValidator.php
4 years ago
Country.php
1 year ago
CountryValidator.php
4 years ago
CssColor.php
1 year ago
CssColorValidator.php
1 year ago
Currency.php
1 year ago
CurrencyValidator.php
4 years ago
Date.php
1 year ago
DateTime.php
1 year ago
DateTimeValidator.php
2 years ago
DateValidator.php
1 year ago
DisableAutoMapping.php
1 year ago
DivisibleBy.php
4 years ago
DivisibleByValidator.php
4 years ago
Email.php
1 year ago
EmailValidator.php
1 year ago
EnableAutoMapping.php
1 year ago
EqualTo.php
4 years ago
EqualToValidator.php
4 years ago
Existence.php
4 years ago
Expression.php
1 year ago
ExpressionLanguageSyntax.php
1 year ago
ExpressionLanguageSyntaxValidator.php
1 year ago
ExpressionValidator.php
1 year ago
File.php
1 year ago
FileValidator.php
4 years ago
GreaterThan.php
4 years ago
GreaterThanOrEqual.php
4 years ago
GreaterThanOrEqualValidator.php
4 years ago
GreaterThanValidator.php
4 years ago
GroupSequence.php
4 years ago
GroupSequenceProvider.php
4 years ago
Hostname.php
1 year ago
HostnameValidator.php
4 years ago
Iban.php
1 year ago
IbanValidator.php
1 year ago
IdenticalTo.php
4 years ago
IdenticalToValidator.php
4 years ago
Image.php
1 year ago
ImageValidator.php
4 years ago
Ip.php
1 year ago
IpValidator.php
4 years ago
IsFalse.php
1 year ago
IsFalseValidator.php
4 years ago
IsNull.php
1 year ago
IsNullValidator.php
4 years ago
IsTrue.php
1 year ago
IsTrueValidator.php
4 years ago
Isbn.php
1 year ago
IsbnValidator.php
1 year ago
Isin.php
1 year ago
IsinValidator.php
4 years ago
Issn.php
1 year ago
IssnValidator.php
4 years ago
Json.php
1 year ago
JsonValidator.php
1 year ago
Language.php
1 year ago
LanguageValidator.php
4 years ago
Length.php
1 year ago
LengthValidator.php
4 years ago
LessThan.php
4 years ago
LessThanOrEqual.php
4 years ago
LessThanOrEqualValidator.php
4 years ago
LessThanValidator.php
4 years ago
Locale.php
1 year ago
LocaleValidator.php
4 years ago
Luhn.php
1 year ago
LuhnValidator.php
4 years ago
Negative.php
4 years ago
NegativeOrZero.php
4 years ago
NotBlank.php
1 year ago
NotBlankValidator.php
4 years ago
NotCompromisedPassword.php
1 year ago
NotCompromisedPasswordValidator.php
1 year ago
NotEqualTo.php
4 years ago
NotEqualToValidator.php
4 years ago
NotIdenticalTo.php
4 years ago
NotIdenticalToValidator.php
4 years ago
NotNull.php
1 year ago
NotNullValidator.php
4 years ago
NumberConstraintTrait.php
4 years ago
Optional.php
4 years ago
Positive.php
4 years ago
PositiveOrZero.php
4 years ago
Range.php
1 year ago
RangeValidator.php
1 year ago
Regex.php
1 year ago
RegexValidator.php
4 years ago
Required.php
4 years ago
Sequentially.php
1 year ago
SequentiallyValidator.php
4 years ago
Time.php
1 year ago
TimeValidator.php
1 year ago
Timezone.php
1 year ago
TimezoneValidator.php
1 year ago
Traverse.php
4 years ago
Type.php
1 year ago
TypeValidator.php
4 years ago
Ulid.php
1 year ago
UlidValidator.php
2 years ago
Unique.php
1 year ago
UniqueValidator.php
1 year ago
Url.php
1 year ago
UrlValidator.php
1 year ago
Uuid.php
1 year ago
UuidValidator.php
4 years ago
Valid.php
1 year ago
ValidValidator.php
4 years ago
ZeroComparisonConstraintTrait.php
1 year ago
index.php
3 years ago
Regex.php
70 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Validator\Constraints; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\Validator\Constraint; |
| 5 | use MailPoetVendor\Symfony\Component\Validator\Exception\InvalidArgumentException; |
| 6 | #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] |
| 7 | class Regex extends Constraint |
| 8 | { |
| 9 | public const REGEX_FAILED_ERROR = 'de1e3db3-5ed4-4941-aae4-59f3667cc3a3'; |
| 10 | protected static $errorNames = [self::REGEX_FAILED_ERROR => 'REGEX_FAILED_ERROR']; |
| 11 | public $message = 'This value is not valid.'; |
| 12 | public $pattern; |
| 13 | public $htmlPattern; |
| 14 | public $match = \true; |
| 15 | public $normalizer; |
| 16 | public function __construct($pattern, ?string $message = null, ?string $htmlPattern = null, ?bool $match = null, ?callable $normalizer = null, ?array $groups = null, $payload = null, array $options = []) |
| 17 | { |
| 18 | if (\is_array($pattern)) { |
| 19 | $options = \array_merge($pattern, $options); |
| 20 | } elseif (null !== $pattern) { |
| 21 | $options['value'] = $pattern; |
| 22 | } |
| 23 | parent::__construct($options, $groups, $payload); |
| 24 | $this->message = $message ?? $this->message; |
| 25 | $this->htmlPattern = $htmlPattern ?? $this->htmlPattern; |
| 26 | $this->match = $match ?? $this->match; |
| 27 | $this->normalizer = $normalizer ?? $this->normalizer; |
| 28 | if (null !== $this->normalizer && !\is_callable($this->normalizer)) { |
| 29 | throw new InvalidArgumentException(\sprintf('The "normalizer" option must be a valid callable ("%s" given).', \get_debug_type($this->normalizer))); |
| 30 | } |
| 31 | } |
| 32 | public function getDefaultOption() |
| 33 | { |
| 34 | return 'pattern'; |
| 35 | } |
| 36 | public function getRequiredOptions() |
| 37 | { |
| 38 | return ['pattern']; |
| 39 | } |
| 40 | public function getHtmlPattern() |
| 41 | { |
| 42 | // If htmlPattern is specified, use it |
| 43 | if (null !== $this->htmlPattern) { |
| 44 | return empty($this->htmlPattern) ? null : $this->htmlPattern; |
| 45 | } |
| 46 | // Quit if delimiters not at very beginning/end (e.g. when options are passed) |
| 47 | if ($this->pattern[0] !== $this->pattern[\strlen($this->pattern) - 1]) { |
| 48 | return null; |
| 49 | } |
| 50 | $delimiter = $this->pattern[0]; |
| 51 | // Unescape the delimiter |
| 52 | $pattern = \str_replace('\\' . $delimiter, $delimiter, \substr($this->pattern, 1, -1)); |
| 53 | // If the pattern is inverted, we can wrap it in |
| 54 | // ((?!pattern).)* |
| 55 | if (!$this->match) { |
| 56 | return '((?!' . $pattern . ').)*'; |
| 57 | } |
| 58 | // If the pattern contains an or statement, wrap the pattern in |
| 59 | // .*(pattern).* and quit. Otherwise we'd need to parse the pattern |
| 60 | if (\str_contains($pattern, '|')) { |
| 61 | return '.*(' . $pattern . ').*'; |
| 62 | } |
| 63 | // Trim leading ^, otherwise prepend .* |
| 64 | $pattern = '^' === $pattern[0] ? \substr($pattern, 1) : '.*' . $pattern; |
| 65 | // Trim trailing $, otherwise append .* |
| 66 | $pattern = '$' === $pattern[\strlen($pattern) - 1] ? \substr($pattern, 0, -1) : $pattern . '.*'; |
| 67 | return $pattern; |
| 68 | } |
| 69 | } |
| 70 |