• This repository has been archived on 27/Dec/2017
  • Stars
    star
    174
  • Rank 218,432 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 10 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[PHP / CLI] Command Line Tool for the Faker PHP library.

Faker Command Line Tool

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/bit3/faker-cli/releases/download/1.4/faker.phar
$ ./faker.phar

As a Composer Install

$ composer create-project bit3/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(), '[email protected]');
INSERT INTO emails (uuid, email) VALUES (UUID(), '[email protected]');
INSERT INTO emails (uuid, email) VALUES (UUID(), '[email protected]');
INSERT INTO emails (uuid, email) VALUES (UUID(), '[email protected]');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'to\'[email protected]');
INSERT INTO emails (uuid, email) VALUES (UUID(), '[email protected]');
INSERT INTO emails (uuid, email) VALUES (UUID(), '[email protected]');
INSERT INTO emails (uuid, email) VALUES (UUID(), '[email protected]');
INSERT INTO emails (uuid, email) VALUES (UUID(), '[email protected]');
INSERT INTO emails (uuid, email) VALUES (UUID(), '[email protected]');
./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.

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.

More Repositories

1

php-remote-objects

[abandoned]
PHP
7
star
2

contao-lazyResize

[abandoned] Lazy resize for Contao.
PHP
6
star
3

contao-screencast3

[abandoned] Source to our contao 3 screencasts.
PHP
5
star
4

string-builder

[PHP] Java like StringBuilder implementation for PHP
PHP
3
star
5

contao-qrcode

[abandoned] QRCode generator for Contao.
PHP
3
star
6

contao-mailer

[abandoned] Mailer Framework for Contao
PHP
3
star
7

service-aware-bundle

[PHP / SF2] Symfony bundle to automatically inject services.
PHP
3
star
8

php-string-builder

[abandoned] Use bit3/string-builder instead!
PHP
3
star
9

contao-open-er2-client

[abandoned] Open ER2 Client API
PHP
2
star
10

mgpm

Multi git project manager
Java
2
star
11

contao-pdo-driver

[abandoned] A PDO based database driver for Contao.
PHP
2
star
12

contao-improvements

[abandoned] Collection of small improvements for Contao.
PHP
2
star
13

assetic-css-crush

[abandoned] The css-crush filter for kriswallsmith/assetic
PHP
2
star
14

contao-compression-api

[abandoned] Contao Compression API.
PHP
2
star
15

contao-theme-reveal-js-basic

[abandoned]
JavaScript
2
star
16

contao-countries-configurator

[abandoned] Configure the countries selection list within the backend.
PHP
2
star
17

contao-magickimages

[abandoned] ImageMagick image rendering module for Contao.
PHP
2
star
18

contao-mysqlmultitriggerframework

[abandoned] Multi Trigger Framework for Contao
PHP
2
star
19

contao-hidepagetitle

[abandoned] Hide the page title and only show website title in Contao.
PHP
2
star
20

contao-miftree

[abandoned] MifTree plugin for Contao.
JavaScript
1
star
21

contao-domainlink

[abandoned] Multi-Domain Solution for Contao.
PHP
1
star
22

composer-global-depends

[abandoned] since packagist give you a list of dependents
PHP
1
star
23

contao-twig-test

[abandoned] Test extension for the Contao Twig integration.
PHP
1
star
24

contao-contaolinks

[abandoned] Extended TinyMCE link editor for Contao.
PHP
1
star
25

contao-website-builder

[abandoned] Automatic generate database records from xml.
PHP
1
star
26

no-op-logger

[PHP] no-op PSR-3 logger.
PHP
1
star
27

contao-associategroups

[abandoned]
PHP
1
star
28

contao-dcxml

[abandoned] POC DC as XML
1
star
29

contao2-autoloader

[abandoned] Extended autoloader for Contao 2.
PHP
1
star
30

contao-yui-compressor

[abandoned] YUI Compressor plugin for compression api.
PHP
1
star
31

contao-thumbnify

[abandoned] Thumbnail generation framework for Contao.
PHP
1
star
32

php-coding-standard

[abandoned]
PHP
1
star
33

php-callback-filter-iterator-polyfill

PHP
1
star
34

contao-pchart-1

[abandoned] Repacked pChart 1 for Contao.
PHP
1
star
35

contao-deeplinks

[abandoned] Deep links support in backend menu for Contao Open Source CMS.
PHP
1
star
36

contao3-poc-namespaces

[abandoned]
PHP
1
star
37

contao3-poc-namespaces-extension

[abandoned]
PHP
1
star
38

contao-deutsche-zahlen

[abandoned] Automatic support of german numbers in Contao.
PHP
1
star
39

contao-theme-plus-jquery

[abandoned] JQuery integration for Theme+
PHP
1
star
40

contao-selectwizard

[abandoned] Select wizard for Contao.
PHP
1
star
41

contao-phpless-extension

[abandoned] Contao php less compiler extension.
PHP
1
star
42

contao-oldbrowser-warning

[abandoned] Shows a Warning page for old/outdated browsers.
PHP
1
star
43

contao-deanedwardspacker

[abandoned] DeanEdwardsPacker plugin for compression api.
PHP
1
star
44

contao-google-api-client

[abandoned] Google API Client for Contao
PHP
1
star
45

contao-addressbook

[abandoned] Addressbook module for contao.
PHP
1
star
46

docker-php

PHP Docker container for developers!
Shell
1
star
47

contao-apccache

[abandoned] APC driven cache class for fast and resource-friendly caching.
PHP
1
star
48

contao-screencast

[abandoned] Extension made in the screencast "How to be(come) a Contao developer"
PHP
1
star
49

contao-language-editor

[abandoned] Use netzmacht/contao-language-editor instead!
PHP
1
star
50

php-benchmark

[abandoned]
PHP
1
star
51

contao-jsminimizer

[abandoned] jsMin plugin for compression api.
PHP
1
star
52

contao-lesscss

[abandoned] less.js plugin for compression api.
PHP
1
star
53

contao-formee-plugin

[abandoned] Formee plugin for Contao.
1
star
54

contao-backup

[abandoned] Simple tool to create a full backup of a contao instance.
PHP
1
star
55

contao-formee-generator

[abandoned] Formee form generator plugin for Contao.
PHP
1
star
56

theme-plus-presentation

Dies ist die Präsentation die auf der Contao Konferenz 2012 vorgestellt wurde.
JavaScript
1
star
57

php-objective-css

[abandoned] Object oriented (less) css parser.
PHP
1
star
58

contao-fancyCheckboxWizard

[abandoned] A fancier checkbox wizard.
PHP
1
star