public static function factory(array $definition) : ?Constraint
    {
        // Make sure a class has been defined.
        if (!isset($definition['class'])) {
            throw new BadDefinitionException('The constraint could not be constructed.');
        }
        $class = $definition['class'];
        $rule = isset($definition['rule']) ? $definition['rule'] : null;
        $error_message = isset($definition['error_message']) ? $definition['error_message'] : null;
        return new $class($rule, $error_message);
    }