malenki / fictif
创建虚拟人物以用于开发数据库!
Requires
- php: >=5.3.0
- malenki/argile: *
This package is not auto-updated.
Last update: 2024-09-24 01:33:34 UTC
README
创建随机的虚构人物或他们的某些信息作为假数据。
仅使用类
为了以更简单的方式生成所需的内容,我设计了几个小型库。因此,如果您只想生成假密码,您也可以。
要将在您的项目中使用我的类,最佳方式是使用 composer。因此,编辑您的 composer.json 并将此添加到 require packages
"require": { "malenki/fictif": "dev-master" }
生日类
创建生日日期非常简单。默认情况下,此类可以生成介于 1900 年和现在之间的日期,返回 `string`。
$bd = new \Malenki\Fictif\Birthday(); $bd->format('d/m/Y'); // if not given, the date will be 'YYYY-MM-DD' echo $bd->generateOne(); // you can use the object in string context too echo $bd;
如果您想,您可以设置最小年和/或最大年。
$bd = new \Malenki\Fictif\Birthday(); $bd->minYear(1967); $bd->maxYear(1980); echo $bd;
您可以生成一个像之前示例中看到的那样,或者生成多个日期。
$bd = new \Malenki\Fictif\Birthday(); $bd->minYear(1967); $bd->maxYear(1980); $arr = $bd->generateMany(23); foreach($arr as $k => $v) { printf('Date #%d: %s', $k + 1, $v); }
简单,不是吗?
电子邮件类
此类非常灵活。
默认情况下,将随机选择域和扩展名,账户是生成的或可以设置的。
因此,域和扩展名可以是固定的(例如,每次生成时都相同),或者您可以放入您的集合。
$m = \Malenki\Fictif\Email(); $m->allowThisDomain(array('one','other')); // add new available domains $m->allowThisExt(array('ru', 'jp')); // add some other extensions //OR, for only one choice: $m->setDomain('foo'); // will be always xxxx@foo.xx $m->setExt('fr'); // will be always xxxx@xxx.fr
与 Birthday 类类似,您有 generateOne() 和 generateMany() 方法。
并且,在字符串上下文中,此类就像字符串一样。
$m = new \Malenki\Fictif\Email(); echo $m;
FirstName 和 LastName 类
这些类有很多来自多个来源的法国示例,因此,您可以获得各种姓氏和名字!
使用 FirstName 类非常简单。要获取一个随机的名字,请执行以下操作
$fn = new \Malenki\Fictif\FirstName(); echo $fn->takeOne(); // or just that in string context: echo $fn;
好的,但如果你只想女性名字,你可以这样做
$fn = new \Malenki\Fictif\FirstName(); $fn->onlyWomen(); echo $fn->takeOne();
对于男性,不出所料
$fn = new \Malenki\Fictif\FirstName(); $fn->onlyMen(); echo $fn->takeOne();
对于既可以是女性也可以是男性的名字
$fn = new \Malenki\Fictif\FirstName(); $fn->onlyBoth(); echo $fn->takeOne();
您也可以一次生成多个
$fn = new \Malenki\Fictif\FirstName(); $fn->onlyWomen(); $arr = $fn->takeMany(20); var_dump($arr); foreach($arr as $k => $v) { printf('Firstname #%d: %s', $k + 1, $v); }
LastName 类使用 takeOne() 和 takeMany() 方法,并且与 FirstName 类的工作方式相同,包括 toString() 行为。
登录类
这个类非常容易使用。只有两种方法:generateOne() 和 generateMany()。与其他类一样,也使用 toString() 行为。
此类生成由伪音节组成的登录名。
所以,就你而言,一个例子
$l = new \Malenki\Fictif\Login(); echo $l->generateOne() //or just: echo $l;
密码类
密码类允许您玩长度和字符。
您可以提供最小和/或最大长度。
$p = new \Malenki\Fictif\Password(); $p->minimal(5)->maximal(15); echo $p->generateOne();
如果您没有设置,最小/最大值为 5 和 20。
您可以设置长度以始终具有相同数量的字符。
$p = new \Malenki\Fictif\Password(); $p->fixedSize(4); echo $p->generateOne(); // you can do that too: echo $p;
您可以添加一些字符…
$p = new \Malenki\Fictif\Password(); $p->allowThis('-_/^$&'); echo $p;
或者只使用字母…
$p = new \Malenki\Fictif\Password(); $p->onlyLetters(); echo $p;
或者只使用数字,您想怎样就怎样!
$p = new \Malenki\Fictif\Password(); $p->onlyDigits(); echo $p
合并所有内容:用户类
用户类允许您一起使用所有前面的类。
每个类都可以通过属性访问。因此,例如,要自定义密码,您可以这样做
$u = new \Malenki\Fictif\User(); $u->password->onlyDigits();
简单,不是吗?
但是,如果您只想使用某些数据,您可以通过调用方法 disableX()(其中 X 是要禁用的属性的名称)来禁用某些数据。因此,要禁用登录生成器,只需这样做
$u = new \Malenki\Fictif\User(); $u->disableLogin();
与其他类一样,User 类有 generateOne() 和 generateMany(),但没有 toString() 功能,并且 generateOne() 返回 stdClass 对象。
还有两种方法可以获取 json 格式的输出
$u = new \Malenki\Fictif\User(); $u->exportOneToJson(); // to have only one user $u->exportManyToJson(10); // to have ten users
使用 CLI 应用
在使用 CLI 应用之前,请确保您已经将 PHP CLI 和 composer 安装在您的系统上。
Git
下载本项目的源代码,或者直接使用 git clone。
git clone https://github.com/malenkiki/fictif.git
然后,进入项目根目录执行以下操作
composer install
仅使用 Composer
您可以使用 composer 来执行
composer create-project malenki/fictif your-dir
使用方法
之后,您可以使用简单的 ./fictif 命令来获取所有可用选项的列表。我认为这个 CLI 脚本中的帮助信息已经足够,无需在此处多做解释了 ;-)
试试看,您可以将结果输出为 JSON、序列化 PHP 或 CSV 格式。
以下行显示了 --help 选项的输出
pc18:fictif michel$ ./fictif --help
Usage: fictif [OPTIONS]…
Create fake poeple to populate some database, website or any other app you want
while developing it. Fictif is the "Lorem ipsum" for data!
Disable some features
--no-password Do not create password
--no-login Do not create login
--no-birthday Do not create birthday
--no-email Do not create email
--only-women Create only women users.
--only-men Create only men users.
Birthday options
--min-year=YYYY Smaller four-digits year allowed for birthday. It
cannot be set before 1900.
--max-year=YYYY Greater year allowed for birthday, into 4 digits.
It cannot be greater than current year.
Email options
--eml-add-domains=LIST Add new domain's names to defaults. Separate them
by comma.
--eml-add-exts=LIST Add new extensions to defaults. Separate each
extensions by a comma.
--eml-set-domain=NAME Use only one domain NAME
--eml-set-ext=EXT Use only one extension EXT
Password options
--pwd-min-size=VALUE Smaller password string length allowed.
--pwd-max-size=VALUE Greater password string length allowed.
--pwd-one-size=VALUE Give size for a unique size password.
--pwd-other=VALUE Give some others characters to use in addition of
characters used by default..
--pwd-only-letters The password must have only letters.
--pwd-only-digits The password must have only digits.
Output options
-n, --amount=VALUE Users's quantity to create.
-j, --json Output result as JSON.
-p, --php Output result as serialized PHP code.
-c, --csv Output result as CSV. Unlike JSON and PHP, you must
provide "output" option too.
-o, --output=FILE File name into where the script writes its output
result. No need to give extension too, this is done
automatically
-h, --help Display this help message and exit
--version Display version information and exit
享受创建虚拟人物吧!