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));
}
我认为这是一个最好的方法。