Mercurial > hg > cmmr2012-drupal-site
comparison vendor/symfony/validator/Constraints/UuidValidator.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
64 /** | 64 /** |
65 * {@inheritdoc} | 65 * {@inheritdoc} |
66 */ | 66 */ |
67 public function validate($value, Constraint $constraint) | 67 public function validate($value, Constraint $constraint) |
68 { | 68 { |
69 if (!$constraint instanceof Uuid) { | |
70 throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Uuid'); | |
71 } | |
72 | |
69 if (null === $value || '' === $value) { | 73 if (null === $value || '' === $value) { |
70 return; | 74 return; |
71 } | 75 } |
72 | 76 |
73 if (!$constraint instanceof Uuid) { | 77 if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) { |
74 throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Uuid'); | |
75 } | |
76 | |
77 if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) { | |
78 throw new UnexpectedTypeException($value, 'string'); | 78 throw new UnexpectedTypeException($value, 'string'); |
79 } | 79 } |
80 | 80 |
81 $value = (string) $value; | 81 $value = (string) $value; |
82 | 82 |
233 ->setCode(Uuid::TOO_LONG_ERROR) | 233 ->setCode(Uuid::TOO_LONG_ERROR) |
234 ->addViolation(); | 234 ->addViolation(); |
235 } | 235 } |
236 | 236 |
237 // Check version | 237 // Check version |
238 if (!in_array($value[self::STRICT_VERSION_POSITION], $constraint->versions)) { | 238 if (!\in_array($value[self::STRICT_VERSION_POSITION], $constraint->versions)) { |
239 $this->context->buildViolation($constraint->message) | 239 $this->context->buildViolation($constraint->message) |
240 ->setParameter('{{ value }}', $this->formatValue($value)) | 240 ->setParameter('{{ value }}', $this->formatValue($value)) |
241 ->setCode(Uuid::INVALID_VERSION_ERROR) | 241 ->setCode(Uuid::INVALID_VERSION_ERROR) |
242 ->addViolation(); | 242 ->addViolation(); |
243 } | 243 } |