mmo/faker-cli
Composer 安装命令:
composer create-project mmo/faker-cli
包简介
A command line command for the Faker PHP library.
README 文档
README
This project is a fork of bit3archive/faker-cli, which is no more maintained - see comment
Faker is a PHP library that generates fake data for you. This is a command line tool for easy generation of fake data in a static way.
Usage
As a Phar (Recommended)
You can find the latest phar on the releases page.
$ wget https://github.com/morawskim/faker-cli/releases/download/2.0.0/faker.phar chmod +x ./faker.phar $ ./faker.phar
As a Composer Install
$ composer create-project mmo/faker-cli
$ cd faker-cli
$ ./bin/faker.php
Parameters and arguments
$ ./bin/faker.php
--locale (-l) # The locale to used. (default: "en_US")
--seed (-s) # The generators seed.
--pattern (-p) # The printf pattern. (default: "%s")
--delimiter (-d) # The delimiter is used by the csv and printf format.
--enclosure (-e) # The enclosure is used by the csv and printf format.
--escape (-E) # The escape character is used by the printf format. (default: "\\")
--format (-f) # The output format (json, xml, csv, php, printf, vprintf) (default: "printf")
--count (-c) # The count of generated data. (default: 1)
<type> # The data type to generate (e.g. "randomDigit", "words", "name", "city")
<args1>..<argsN> # Arguments for the type, e.g. "words 5" will generate 5 words.
Single value generator example
$ ./bin/faker.php word
culpa
consequatur
quisquam
recusandae
asperiores
accusamus
nihil
repellat
vero
omnis
Multi value generator example
$ ./bin/faker.php --count 5 words 2
culpa,consequatur
quisquam,recusandae
asperiores,accusamus
nihil,repellat
vero,omnis
Output formats
You can use different output formats by definint the --format option. JSON is the default format.
JSON output
$ ./bin/faker.php word
[
"culpa",
"consequatur",
"quisquam",
"recusandae",
"asperiores",
"accusamus",
"nihil",
"repellat",
"vero",
"omnis"
]
$ ./bin/faker.php --count 5 words 2
[
[
"culpa",
"consequatur"
],
[
"quisquam",
"recusandae"
],
[
"asperiores",
"accusamus"
],
[
"nihil",
"repellat"
],
[
"vero",
"omnis"
]
]
XML output
$ ./bin/faker.php --format xml word
<?xml version="1.0"?>
<array>
<item>culpa</item>
<item>consequatur</item>
<item>quisquam</item>
<item>recusandae</item>
<item>asperiores</item>
<item>accusamus</item>
<item>nihil</item>
<item>repellat</item>
<item>vero</item>
<item>omnis</item>
</array>
CSV output
$ ./bin/faker.php --format csv word
culpa
consequatur
quisquam
recusandae
asperiores
accusamus
nihil
repellat
vero
omnis
PHP output
$ ./bin/faker.php --format php word
array (
0 => 'culpa',
1 => 'consequatur',
2 => 'quisquam',
3 => 'recusandae',
4 => 'asperiores',
5 => 'accusamus',
6 => 'nihil',
7 => 'repellat',
8 => 'vero',
9 => 'omnis',
)
printf and vprintf output
The printf and vprintf output are mostly equal. But printf is designed for single value generator types e.g. safeEmail and vprintf is designed for multi value generator types e.g. words 5.
$ ./bin/faker.php --format printf \
--pattern "INSERT INTO emails (uuid, email) VALUES (UUID(), %s);" \
--enclosure "'" \
safeEmail
INSERT INTO emails (uuid, email) VALUES (UUID(), 'dbednar@example.com');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'xhettinger@example.net');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'gerald62@example.org');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'miles91@example.com');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'to\'conner@example.com');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'bridgette.runolfsdottir@example.com');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'fgoldner@example.org');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'grimes.leo@example.org');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'lilian.reynolds@example.net');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'ratke.darlene@example.net');
./bin/faker.php --format vprintf \
--pattern "INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), %s, %s, %s);" \
--enclosure "'" \
words 3
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'est', 'illo', 'consequuntur');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'dolorem', 'temporibus', 'commodi');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'sint', 'reiciendis', 'sint');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'sunt', 'eum', 'id');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'tempora', 'rerum', 'occaecati');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'corrupti', 'impedit', 'doloribus');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'amet', 'consectetur', 'repudiandae');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'est', 'id', 'amet');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'odio', 'facere', 'nesciunt');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'voluptas', 'quia', 'rerum');
You can also use printf with multi value generator types, which will joined by the --delimiter char, which is , by default.
$ ./bin/faker.php --format printf \
--pattern "INSERT INTO words (uuid, words) VALUES (UUID(), %s);" \
--delimiter ' / ' \
--enclosure "'" \
words 10
INSERT INTO words (uuid, words) VALUES (UUID(), 'est / illo / consequuntur / dolorem / temporibus / commodi / sint / reiciendis / sint / sunt');
INSERT INTO words (uuid, words) VALUES (UUID(), 'eum / id / tempora / rerum / occaecati / corrupti / impedit / doloribus / amet / consectetur');
INSERT INTO words (uuid, words) VALUES (UUID(), 'repudiandae / est / id / amet / odio / facere / nesciunt / voluptas / quia / rerum');
INSERT INTO words (uuid, words) VALUES (UUID(), 'ad / sed / esse / sed / exercitationem / sed / et / rem / esse / excepturi');
INSERT INTO words (uuid, words) VALUES (UUID(), 'animi / minus / qui / perferendis / quo / repudiandae / aliquam / dolorem / voluptas / fugiat');
INSERT INTO words (uuid, words) VALUES (UUID(), 'at / odit / dolorem / a / aperiam / dignissimos / ipsa / sunt / consequatur / alias');
INSERT INTO words (uuid, words) VALUES (UUID(), 'accusantium / voluptatum / autem / nobis / cumque / neque / modi / iure / voluptatem / error');
INSERT INTO words (uuid, words) VALUES (UUID(), 'molestiae / consequatur / alias / eligendi / corrupti / illum / commodi / molestiae / aut / repellat');
INSERT INTO words (uuid, words) VALUES (UUID(), 'id / quisquam / et / sit / consequuntur / aut / et / ullam / asperiores / molestiae');
INSERT INTO words (uuid, words) VALUES (UUID(), 'cupiditate / culpa / voluptatem / et / mollitia / dolor / sit / nisi / praesentium / qui');
It is recommend to use the --enclosure option. each occurrence of the --enclosure char will be escaped with the --escape char, which is \\ by default.
Completion
Currently only bash is supported. Your faker-cli.php or faker.phar must be in your PATH env.
Phar
You must download https://raw.githubusercontent.com/morawskim/faker-cli/master/completions/bash_completion.sh somewhere and source this file in .bashrc
source DOWNLOAD_PATH/bash_completion.sh
Composer
You only need source completions/bash_completion.sh in your .bashrc
source PATH_TO_FAKER_CLI/completions/bash_completion.sh
Build your own Phar
Install and run php-box:
$ curl -LSs https://box-project.github.io/box2/installer.php | php
$ ./box.phar build
License
Faker Command Line Tool is released under the MIT Licence. See the bundled LICENSE file for details.
mmo/faker-cli 适用场景与选型建议
mmo/faker-cli 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 04 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「faker」 「fixtures」 「data」 「cli」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mmo/faker-cli 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mmo/faker-cli 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mmo/faker-cli 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Testing object factory for PHP
Testing object factory for PHP
Adds the EDTF data type to Wikibase
Plugin to compare fixtures with live DB tables
A simple library that allows transform any kind of data to native php data or whatever
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-04-10