1
我正在使用這個庫,並且遇到了一個我沒有解決的問題。這可能限制fzaninotto上的一些字符串格式化器Faker
我喜歡限制大小的一些字段,例如userName(Faker \ Provider \ Internet)。我認爲ot不是好主意使用字符串與255這個領域,並像限制到15.
在我的表的種子生成一些崩潰後,我讀代碼。
protected static $userNameFormats = array(
'{{lastName}}.{{firstName}}',
'{{firstName}}.{{lastName}}',
'{{firstName}}##',
'?{{lastName}}',
);
public function userName()
{
$format = static::randomElement(static::$userNameFormats);
$username = static::bothify($this->generator->parse($format));
return strtolower(static::transliterate($username));
}
用於我的程序,我認爲創建一個分叉。在這個分支修改代碼
protected static $userNickFormats = array(
'{{firstName}}',
'{{firstName}}#',
'{{firstName}}##',
'{{firstName}}###',
'?{{lastName}}##',
);
public function userNick($limit = 15)
{
$format = static::randomElement(static::$userNickFormats);
$username = static::bothify($this->generator->parse($format));
while (strlen($username) > $limit) {
$username = static::bothify($this->generator->parse($format));
}
return strtolower(static::transliterate($username));
}
我認爲這是一個最好的方法。