Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/validator/Constraints/UuidValidator.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
14 use Symfony\Component\Validator\Constraint; | 14 use Symfony\Component\Validator\Constraint; |
15 use Symfony\Component\Validator\ConstraintValidator; | 15 use Symfony\Component\Validator\ConstraintValidator; |
16 use Symfony\Component\Validator\Exception\UnexpectedTypeException; | 16 use Symfony\Component\Validator\Exception\UnexpectedTypeException; |
17 | 17 |
18 /** | 18 /** |
19 * Validates whether the value is a valid UUID per RFC 4122. | 19 * Validates whether the value is a valid UUID (also known as GUID). |
20 * | |
21 * Strict validation will allow a UUID as specified per RFC 4122. | |
22 * Loose validation will allow any type of UUID. | |
23 * | |
24 * For better compatibility, both loose and strict, you should consider using a specialized UUID library like "ramsey/uuid" instead. | |
20 * | 25 * |
21 * @author Colin O'Dell <colinodell@gmail.com> | 26 * @author Colin O'Dell <colinodell@gmail.com> |
22 * @author Bernhard Schussek <bschussek@gmail.com> | 27 * @author Bernhard Schussek <bschussek@gmail.com> |
23 * | 28 * |
24 * @see http://tools.ietf.org/html/rfc4122 | 29 * @see http://tools.ietf.org/html/rfc4122 |
25 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier | 30 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier |
31 * @see https://github.com/ramsey/uuid | |
26 */ | 32 */ |
27 class UuidValidator extends ConstraintValidator | 33 class UuidValidator extends ConstraintValidator |
28 { | 34 { |
29 // The strict pattern matches UUIDs like this: | 35 // The strict pattern matches UUIDs like this: |
30 // xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx | 36 // xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx |
238 | 244 |
239 // Check variant - first two bits must equal "10" | 245 // Check variant - first two bits must equal "10" |
240 // 0b10xx | 246 // 0b10xx |
241 // & 0b1100 (12) | 247 // & 0b1100 (12) |
242 // = 0b1000 (8) | 248 // = 0b1000 (8) |
243 if ((hexdec($value[self::STRICT_VARIANT_POSITION]) & 12) !== 8) { | 249 if (8 !== (hexdec($value[self::STRICT_VARIANT_POSITION]) & 12)) { |
244 $this->context->buildViolation($constraint->message) | 250 $this->context->buildViolation($constraint->message) |
245 ->setParameter('{{ value }}', $this->formatValue($value)) | 251 ->setParameter('{{ value }}', $this->formatValue($value)) |
246 ->setCode(Uuid::INVALID_VARIANT_ERROR) | 252 ->setCode(Uuid::INVALID_VARIANT_ERROR) |
247 ->addViolation(); | 253 ->addViolation(); |
248 } | 254 } |