@param        $data
@param string $default
@param array $options
@param bool $float

@return array|mixed|string
541408
public function number($data, $default = '0', array $options = [], $float = false)
    {

        list($filter, $flags, $parameters) = $this->readFiltersAndFlags(
            $options,
            ($float) ? static::FILTER_FLOAT : static::FILTER_NUMBER
        );

        //push custom filters and flags from options to their respective array;
        $number = $this->scrub($data, $filter, $parameters);

        //@TODO validate is number before return
        return (empty($number)) ? $default : $number;

    }
507581
public function insert(array $data, $options = [], $replace = false)
    {
        // 分析并处理数据
        $data = $this->parseData($data, $options);
        if (empty($data)) {
            return 0;
        }
        $fields = array_keys($data);
        $values = array_values($data);

        $sql = str_replace(
            ['%INSERT%', '%TABLE%', '%FIELD%', '%DATA%', '%COMMENT%'],
            [
                $replace ? 'REPLACE' : 'INSERT',
                $this->parseTable($options['table'], $options),
                implode(' , ', $fields),
                implode(' , ', $values),
                $this->parseComment($options['comment']),
            ], $this->insertSql);

        return $sql;
    }
766477
public function provide($data = null, array $options = [])
    {
        $valueLabels = [
            0 => '0',
            1 => '1',
        ];

        if (empty($options['valueLabels'])) {
            $options['valueLabels'] = $valueLabels;
        }

        if (!is_array($options['valueLabels'])) {
            throw new InvalidArgumentException("valueLabels option is not an array");
        }

        if (count($options['valueLabels']) < 2) {
            throw new InvalidArgumentException("valueLabels option has insufficient items");
        }

        $result = $data ? $options['valueLabels'][1] : $options['valueLabels'][0];
        $result = (string)$result;

        return $result;
    }
1077744
public function getValueFromData($data, $default = null)
    {
        $fieldName = $this->valueFrom ?: $this->fieldName;
        return $this->getFieldNameFromData($fieldName, $data, $default);
    }
1169267
protected function encode($data, $options = 0)
    {
        // Check is already json string.
        if (is_string($data) && strlen($data) >= 1) {
            $firstChar = $data[0];

            if (in_array($firstChar, ['[', '{', '"'])) {
                return $data;
            }
        }

        // Clear json_last_error()
        json_encode(null);

        $json = json_encode($data, $options);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \UnexpectedValueException(sprintf('JSON encode failure: %s', json_last_error_msg()));
        }

        return $json;
    }
484507
public function deserialize($data, BooleanQuestion $question = null, array $options = [])
    {
        if (empty($question)) {
            $question = new BooleanQuestion();
        }

        $this->deserializeChoices($question, $data['choices'], $data['solutions'], $options);

        return $question;
    }
425187
public function email($data, $default = 'missing@example.com', $options = [])
    {
        //FILTER_SANITIZE_EMAIL

        //check custom filters and flags in options array;
        list($filter, $flags, $parameters) = $this->readFiltersAndFlags(
            $options,
            static::FILTER_EMAIL
        );
        //push custom filters and flags from options to their respective array;

        $email = $this->scrub($data, $filter, $parameters);

        //@TODO valid is email with $this->validate before return;
        return (string)(empty($email) ? $default : $email);
    }
252060
public function batchQuery($defaultScenario, $data = [], array $options = [])
    {
        $batch = isset($options['batch']) ? (bool) $options['batch'] : true;
        $options['batch'] = $batch;

        if (!$batch) {
            $val = reset($data);
            $key = key($data);
            $data = $val;
        }

        $result = $this->query($defaultScenario, $data, $options);

        if (!$batch) {
            $result = [$key => $result];
        }

        return $result;
    }
1078431
public function getFloat(string $index, $default = null, array $options = []) : ?float
    {
        return $this->getCastedValue('float', $index, $default, $options);
    }
265111
public function escaped($data, $default = "", $options = [])
    {
        //FILTER_SANITIZE_MAGIC_QUOTES
        //FILTER_SANITIZE_SPECIAL_CHARS
        $filter = static::FILTER_ESCAPED;
        //FILTER_SANITIZE_NUMBER_INT

        $escaped = $this->getVar($name, $filter, $default, $verb, $options);

        //@TODO validate is interger before return
        return $escaped;
    }
688623
public static function get(array $data, $key, $default = null)
	{
		if ($key === null) {
			return $data;
		}

		if (is_array($key)) {
			return static::getArray($data, $key, $default);
		}

		foreach (explode('.', $key) as $segment) {
			if (!is_array($data)) {
				return $default;
			}

			if (!array_key_exists($segment, $data)) {
				return $default;
			}

			$data = $data[$segment];
		}

		return $data;
	}
1089753
public function save($data = null, array $options = []) {
        if ($data) {
            $this->data($data);
        }

        return $this->getRepository()->save($this, $options);
    }
823633
public static function getArray(
        array $options,
        string $key,
        $default = null
    ) {
        if (array_key_exists($key, $options)) {
            return (array)$options[$key];
        }

        return $default;
    }
909673
protected function getDefaultOptions($data = null, array $options = []) : array
    {
        $result = [
            'type' => $options['fieldDefinitions']->getType(),
            'label' => $options['label'],
            'operators' => $this->getSearchOperators($data, $options),
            'input' => [
                'content' => '',
            ],
        ];

        return $result;
    }
827482
public static function float(&$value, $options = ['max'=>null, 'min'=>null, 'default'=>null])
    {
        $value = (float)$value;
        self::processNum($value, $options);
        return $value;
    }
1234478
public function provide($data = null, array $options = [])
    {
        $result = parent::provide($data, $options);
        $errorResponse = sprintf(parent::VALUE_NOT_FOUND_HTML, $data);

        //In case the result is the same with the errorResponse then return the error
        if (empty($result) || $errorResponse == $result) {
            return $result;
        } else {
            return static::getIcon($data, $result);
        }
    }
215802
public static function create(array $data, array $options = []) {
        /** @type \Titon\Model\Model $model */
        $model = new static();
        $model->fill($data);

        if ($model->save($options)) {
            return $model;
        }

        return null;
    }