插入记录并获取自增ID
@access public
@param array   $data     数据
@param boolean $replace  是否replace
@param string  $sequence 自增序列名
@return integer|string
344790
public function insertGetId(array $data, $replace = false, $sequence = null)
    {
        return $this->insert($data, $replace, true, $sequence);
    }
139176
public function insertGetId(array $values, $sequence = null)
    {
        $result = $this->collection->insertOne($values);

        if (1 == (int) $result->isAcknowledged()) {
            if (is_null($sequence)) {
                $sequence = '_id';
            }

            // Return id
            return $sequence == '_id' ? trim($result->getInsertedId()) : $values[$sequence];
        }

        return null;
    }
468705
public function insert(Query $query, $replace = false, $getLastInsID = false, $sequence = null)
    {
        // 分析查询表达式
        $options = $query->getOptions();

        // 生成SQL语句
        $sql = $this->builder->insert($query, $replace);

        $bind = $query->getBind();

        if (!empty($options['fetch_sql'])) {
            // 获取实际执行的SQL语句
            return $this->getRealSql($sql, $bind);
        }

        // 执行操作
        $result = '' == $sql ? 0 : $this->execute($sql, $bind, $query);

        if ($result) {
            $sequence  = $sequence ?: (isset($options['sequence']) ? $options['sequence'] : null);
            $lastInsId = $this->getLastInsID($sequence);

            $data = $options['data'];

            if ($lastInsId) {
                $pk = $query->getPk($options);
                if (is_string($pk)) {
                    $data[$pk] = $lastInsId;
                }
            }

            $query->setOption('data', $data);

            $query->trigger('after_insert');

            if ($getLastInsID) {
                return $lastInsId;
            }
        }

        return $result;
    }
1370732
public static function strIreplace($search, $replace, $str, $count = null, $encoding = null)
    {
        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;

        if (!is_array($search)) {
            $slen = strlen($search);

            if ($slen == 0) {
                return $str;
            }

            $lendif = strlen($replace) - strlen($search);
            $search = static::strtolower($search, $encoding);
            $search = preg_quote($search, '/');
            $lstr = static::strtolower($str, $encoding);
            $i = 0;
            $matched = 0;

            while (preg_match('/(.*)' . $search . '/Us', $lstr, $matches)) {
                if ($count !== null && $i === $count) {
                    break;
                }

                $mlen = strlen($matches[0]);
                $lstr = substr($lstr, $mlen);

                $str = substr_replace($str, $replace, $matched + strlen($matches[1]), $slen);
                $matched += $mlen + $lendif;
                $i++;
            }

            return $str;
        } else {
            $keys = array_keys($search);

            foreach ($keys as $k) {
                if (is_array($replace)) {
                    if (array_key_exists($k, $replace)) {
                        $str = static::strIreplace($search[$k], $replace[$k], $str, $count, $encoding);
                    } else {
                        $str = static::strIreplace($search[$k], '', $str, $count, $encoding);
                    }
                } else {
                    $str = static::strIreplace($search[$k], $replace, $str, $count, $encoding);
                }
            }

            return $str;
        }
    }
80961
public function replace($search, $replace, &$count = null)
    {
        $this->string = str_replace($search, $replace, $this->string, $count);

        return $this;
    }
1216081
public function where($where, $replacement = array())
    {
        if (is_array($where)) {
            $tmp = array();
            foreach ($where as $k => $v) {
                $tmp[] = !is_string($v) ? $k . "=" . $v : $k . "='" . $this->escape_string($v) . "'";
            }
            $where = implode(' AND ', $tmp);
        } elseif (is_string($where) && !empty($replacement)) {
            // 支持model->where("id>? and name=?", [12, "name"])
            $i = 0;
            $where = preg_replace_callback(["/(\?)/"], function () use (&$i, &$replacement) {
                $v = $replacement[$i++];
                return !is_string($v) ? ( !is_null($v) ? $v : "''" ) : "'" . $this->escape_string($v) . "'";
            }, $where);
        }

        if (empty($this->where)) {
            $this->where = $where;
        } else {
            $this->where .= " AND " . $where;
        }

        // dd($this->where);

        return $this;
    }
26573
public function insertGetId(array $values, $sequence = null)
    {
        $result = parent::insertGetId($values, $sequence);

        $this->handler->setBuilder($this)
            ->invalidateQuery(Reflector::QUERY_TYPE_INSERT, $values);

        return $result;
    }
613839
public function replace(array $words, $replace, $text)
    {
        if (! $this->isHan($text)) {
            return $this->replaceExact($words, $replace, $text);
        }

        return Replace\Chinese::replace($words, $replace, $text);
    }
203734
public static function trans($string, $replace = [])
    {
        $text = \JText::_($string);

        foreach ($replace as $key => $value) {
            $text = str_replace($key, $value, $text);
        }

        return $text;
    }
211913
public function compileInsertGetId(Builder $query, $values, $sequence) {
    $this->beforePut($values);
    $this->remapWheres($query);
    $sql = $this->grammar->compileInsertGetId($query, $values, $sequence);

    if($this->replace_into) {
      $sql = preg_replace('/^insert into/i', 'replace into', $sql);
      $this->replace_into = false;
    }

    return $sql;
  }
875211
public function update($table = '', $data = array())
    {
        if (empty($data)) {
            die('数据不能为空！');
        }

        $sql = 'UPDATE '.$table.' SET ';
        //字段名处理
        foreach ($data as $k => $v) {
            $sql = $sql.$k.'=:'.$k.',';

            $this->bindParam($k, $v);
        }
        $sql = rtrim($sql, ',');
        $sql = $sql.' WHERE id='.$data['id'];

        return $this->execute($sql);
    }
537771
public function regexplace($pattern, $replacement)
    {
        $result = preg_replace($pattern, $replacement, $this->getInternalValue());
        $this->setInternalValue($result);

        return $this;
    }
1336695
public function replace($value, $pattern, $replacement = '', $limit = -1)
    {
        $this->assertNoEval($pattern);
        
        if (!isset($value)) {
            return null;
        }
        
        return preg_replace($pattern, $replacement, $value, $limit);
    }
1367717
public function substrReplace($replace, $start, $offset = null)
    {
        return $this->cloneInstance(
            function (StringObject $new) use ($replace, $start, $offset) {
                $new->string = Mbstring::substrReplace($new->string, $replace, $start, $offset, $this->encoding);
            }
        );
    }
1311607
protected static function inserts_replacing_recursive ($data, $insert) {
		if (is_array($data)) {
			/** @noinspection ForeachSourceInspection */
			foreach ($data as &$d) {
				$d = static::inserts_replacing_recursive($d, $insert);
			}
			return $data;
		}
		foreach ($insert as $i => $d) {
			$data = str_replace("\$i[$i]", $d, $data);
		}
		return $data;
	}
761755
final protected static function replaceKey($data, $search, $replace)
    {
        foreach ($data as $key => $value) {
            if (is_array($value)) {
                $data[$key] = $value = self::replaceKey($data[$key], $search, $replace);
            }
            if ($key == $search) {
                $data[$replace] = $value;
                unset($data[$search]);
            }
        }

        return $data;
    }
1044274
public function set($data, $replacement = array())
    {
        if (is_array($data)) {
            foreach ($data as $k => $v) {
                $data[$k] = "'" . $this->escape_string($v) . "'";
            }

            $this->data += $data;
        } else if (is_string($data) && !empty($replacement)) {
            // 支持model->set("cid=? and name=?", [12, "name"])
            $i = 0;

            $data = preg_replace_callback(["/(\?)/"], function () use (&$i, &$replacement) {
                $v = $replacement[$i++];
                return !is_string($v) ? $v : "'" . $this->escape_string($v) . "'";
            }, $data);

            $this->data = $data;
        } else {
            throw_error('model::set参数错误, 只接收string或array类型');
        }

        return $this;
    }