格式化字段值，按以下顺序尝试: data_format|field_name|base_type|data_type
@param mixed  $field
@param string $value
@param string
5472
static public function formatValue($field, $value=null)
    {
        $methods = [];
        if (isset($field['data_format']) && $field['data_format']) {
            $methods[] = $field['data_format'];
        }
        $methods[] = $field['field_name'];
        if (isset($field['base_type']) && $field['base_type']) {
            $methods[] = $field['base_type'];
        }
        $methods[] = $field['data_type'];
        
        foreach ($methods as $m) {
            if (method_exists(get_called_class(), $m)) {
                return static::$m($value);
            }
        }
        
        $data_type = strtolower($field['data_type']);
        if (preg_match('/int/', $data_type)) {
            $value = intval($value);
        } elseif (preg_match('/decimal/', $data_type)) {
            $precision = isset($field['precision']) ? $field['precision'] : 6;
            $value = static::decimal($value, $precision);
        } elseif (preg_match('/text/', $data_type)) {
            $value = static::text($value);
        } else {
            $value = static::input($value);
        }
        
        return $value;
    }
626884
public function set($field, $value) {
        $parser = $this->getParser($field);
        $this->_properties[$field] = $parser->parse($value);
        return $this;
    }
1138444
protected function bindParam($field, $value)
    {
        $field = ':L_' . preg_replace('/\./', '__', $field); //加入前缀，预防与其他类产生的绑定变量污染，替换字段中的'.'为下划线
        if (!isset(self::$counter[$field])) {
            self::$counter[$field] = 0;
        }
        $bind_param                = $field . self::$counter[$field]++; //绑定变量名
        $this->params[$bind_param] = $value; //记录绑定变量值
        return $bind_param;

    }
1034762
public function normalizeValue($field, $value)
    {
        if ($value === null || !$this->_types) {
            return $value;
        }

        if (!isset($this->_types[$field])) {
            throw new MisuseException(['`:field` field type is not defined', 'field' => $field]);
        }

        $type = $this->_types[$field];

        if ($type === 'string') {
            return is_string($value) ? $value : (string)$value;
        } elseif ($type === 'int') {
            return is_int($value) ? $value : (int)$value;
        } elseif ($type === 'float') {
            return is_float($value) ? $value : (float)$value;
        } elseif ($type === 'objectid') {
            return is_scalar($type) ? new ObjectId($value) : $value;
        } elseif ($type === 'bool') {
            return is_bool($value) ? $value : (bool)$value;
        } elseif ($type === 'array') {
            return (array)$value;
        } else {
            throw new InvalidValueException(['normalize `:type` type value is not supported', 'type' => $type]);
        }
    }
914078
public function addField($field, $value=null) {
        $this->fields[] = $field;
        if ($value != null) $this->set($field, $value);
    }
91640
public function set_select($field = '', $value = '', $default = false)
    {
        if (!$this->ran()) {
            return ($default === true) ? ' selected="selected"' : '';
        }

        $field = (isset($this->_field_data[$field]['postdata']) ? $this->_field_data[$field]['postdata']: '');
        $value = (string) $value;
        if (is_array($field)) {
        // Note: in_array('', array(0)) returns true, do not use it
            foreach ($field as $v) {
                if ($value === $v) {
                    return ' selected="selected"';
                }
            }

            return '';
        } elseif (($field === '' || $value === '') || ($field !== $value)) {
            return '';
        }

        return ' selected="selected"';
    }
1306892
public function setFieldValue($document, $field, $value)
    {
        $this->reflFields[$field]->setValue($document, $value);
    }
445085
protected function parseValue(FieldBuilder $field, $value = null)
    {
        $parsedValue = null;

        // No data found, define a default by field type.
        switch ($field->getFieldType())
        {

            case 'checkbox':
            case 'checkboxes': // @todo remove this checkboxes statement for next major update.
            case 'radio':
            case 'select':
            case 'collection':

                $parsedValue = $this->parseArrayable($field, $value);
                break;

            case 'infinite':

                // Check for the registered fields and their default value if one.
                $parsedValue = $this->parseInfinite($field, $value);
                break;

            // Text
            // Textarea
            // Password
            // Media
            // Editor
            default:
                $parsedValue = $this->parseString($field, $value);
        }

        return $parsedValue;
    }
290131
public function offsetSet($offset, $value)
    {
        $field = $this->dataField;

        if ($offset !== null) {
            $this->{$field}[$offset] = $value;
        } else {
            array_push($this->{$field}, $value);
        }
    }
823041
private function parseString(FieldBuilder $field, $value = '')
    {
        return (empty($value) && isset($field['default'])) ? $field['default'] : $value;
    }
1147179
static function preProcessValue( $value, $fieldType )
    {
        switch( $fieldType )
        {
            case 'date':
            {
                if ( is_numeric( $value ) )
                {
                    $value = self::convertTimestampToDate( $value );
                }
                // Flag this as not to index
                else
                {
                    $value = null;
                }

            } break;

            case 'boolean':
            {
                if ( is_numeric( $value ) )
                {
                    $value = $value ? 'true' : 'false';
                }
            } break;

            default:
            {
                // Do nothing yet.
            } break;
        }

        return $value;
    }
1112795
public function setFieldValue(string $field, int $value) : bool
        {
                return $this->_redis->zadd($this->_key, $value, $field) > 0 ? true : false;
        }
127258
public function set($field, $value, $type = 'HOME')
    {
        $field   = strtolower($field);
        $type_uc = strtoupper($type);

        switch ($field) {
        case 'name':
        case 'displayname':
            $this->raw['FN'][0][0] = $this->displayname = $value;
            break;

        case 'surname':
            $this->raw['N'][0][0] = $this->surname = $value;
            break;

        case 'firstname':
            $this->raw['N'][0][1] = $this->firstname = $value;
            break;

        case 'middlename':
            $this->raw['N'][0][2] = $this->middlename = $value;
            break;

        case 'prefix':
            $this->raw['N'][0][3] = $value;
            break;

        case 'suffix':
            $this->raw['N'][0][4] = $value;
            break;

        case 'nickname':
            $this->raw['NICKNAME'][0][0] = $this->nickname = $value;
            break;

        case 'organization':
            $this->raw['ORG'][0][0] = $this->organization = $value;
            break;

        case 'photo':
            if (strpos($value, 'http:') === 0) {
                // TODO: fetch file from URL and save it locally?
                $this->raw['PHOTO'][0] = array(0 => $value, 'url' => true);
            }
            else {
                $this->raw['PHOTO'][0] = array(0 => $value, 'base64' => (bool) preg_match('![^a-z0-9/=+-]!i', $value));
            }
            break;

        case 'email':
            $this->raw['EMAIL'][] = array(0 => $value, 'type' => array_filter(array('INTERNET', $type_uc)));
            $this->email[] = $value;
            break;

        case 'im':
            // save IM subtypes into extension fields
            $typemap = array_flip($this->immap);
            if ($field = $typemap[strtolower($type)]) {
                $this->raw[$field][] = array(0 => $value);
            }
            break;

        case 'birthday':
        case 'anniversary':
            if (($val = rcube_utils::anytodatetime($value)) && ($fn = self::$fieldmap[$field])) {
                $this->raw[$fn][] = array(0 => $val->format('Y-m-d'), 'value' => array('date'));
            }
            break;

        case 'address':
            if ($this->addresstypemap[$type_uc]) {
                $type = $this->addresstypemap[$type_uc];
            }

            $value = $value[0] ? $value : array('', '', $value['street'], $value['locality'], $value['region'], $value['zipcode'], $value['country']);

            // fall through if not empty
            if (!strlen(join('', $value))) {
                break;
            }

        default:
            if ($field == 'phone' && $this->phonetypemap[$type_uc]) {
                $type = $this->phonetypemap[$type_uc];
            }

            if (($tag = self::$fieldmap[$field]) && (is_array($value) || strlen($value))) {
                $this->raw[$tag][] = (array) $value;
                if ($type) {
                    $index   = count($this->raw[$tag]) - 1;
                    $typemap = array_flip($this->typemap);
                    $this->raw[$tag][$index]['type'] = explode(',', $typemap[$type_uc] ?: $type);
                }
            }
            else {
                unset($this->raw[$tag]);
            }

            break;
        }
    }
1284278
public function setFieldValue($fieldName, $value)
    {
        if (isset($this->originalValues[$fieldName])
            && $this->originalValues[$fieldName] === $value
        ) {
            # the given value is the same as the original value;
            # ignore any given value
            unset($this->givenValues[$fieldName]);
        } elseif (isset($this->originalValues[$fieldName])
            && $this->originalValues[$fieldName] !== $value
            && isset($this->defaults[$fieldName])
            && $this->defaults[$fieldName] === $value
        ) {
            # the given value is the same as a default value, but different from
            # the original value; change it
            $this->givenValues[$fieldName] = $value;
        } elseif (isset($this->defaults[$fieldName])
            && $this->defaults[$fieldName] === $value
        ) {
            # the given value is the same as the default value;
            # ignore any given value
            unset($this->givenValues[$fieldName]);
        } else {
            $this->givenValues[$fieldName] = $value;
        }
        return $this;
    }
393402
public function addField(string $field, string $value): self
    {
        $this->fields[$field] = $value;

        return $this;
    }
452346
public function set($field, $value, $type = 0)
    {
        $this->_write_fields[] = $field;
        $this->_write_values[] = $value;
        $this->_write_field_types[] = $type;

        return $this;
    }
82033
public function set($field, $value)
    {
        if ($field === 'author_types' && !is_array($value)) {
            $value = explode(',', $value);
        }

        $this->_settings[$field] = $value;
    }