use Symfony\Component\Validator\Exception\UnexpectedTypeException;
/**
- * Validates whether the value is a valid UUID per RFC 4122.
+ * Validates whether the value is a valid UUID (also known as GUID).
+ *
+ * Strict validation will allow a UUID as specified per RFC 4122.
+ * Loose validation will allow any type of UUID.
+ *
+ * For better compatibility, both loose and strict, you should consider using a specialized UUID library like "ramsey/uuid" instead.
*
* @author Colin O'Dell <colinodell@gmail.com>
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @see http://tools.ietf.org/html/rfc4122
* @see https://en.wikipedia.org/wiki/Universally_unique_identifier
+ * @see https://github.com/ramsey/uuid
*/
class UuidValidator extends ConstraintValidator
{
// 0b10xx
// & 0b1100 (12)
// = 0b1000 (8)
- if ((hexdec($value[self::STRICT_VARIANT_POSITION]) & 12) !== 8) {
+ if (8 !== (hexdec($value[self::STRICT_VARIANT_POSITION]) & 12)) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Uuid::INVALID_VARIANT_ERROR)