https://github.com/rootinc/faker-bonus
Extra Faker Formatters/Providers for PHP
https://github.com/rootinc/faker-bonus
Last synced: 29 days ago
JSON representation
Extra Faker Formatters/Providers for PHP
- Host: GitHub
- URL: https://github.com/rootinc/faker-bonus
- Owner: rootinc
- License: mit
- Created: 2020-02-27T23:06:27.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-04T15:30:46.000Z (over 6 years ago)
- Last Synced: 2026-04-21T07:47:28.852Z (2 months ago)
- Language: PHP
- Homepage:
- Size: 52.7 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# faker-bonus
[](https://app.codeship.com/projects/387568)
A handy set of extra Faker Formatters/Providers for [fzaninotto/faker](https://github.com/fzaninotto/faker) built to integrate with Laravel or
any PHP project that uses Faker.
## Contents
1. [Installation](#installation)
1. [Usage](#basic-usage)
1. [Basic Usage](#basic-usage)
1. [Laravel Installation](#laravel-usage)
1. [Formatters](#formatters)
1. [Hashtag](#hashtag)
1. [Mention](#mention)
1. [Tweet Text](#tweet-text)
1. [Testing](#testing)
1. [Acknowledgements](#acknowledgement)
## Installation
```bash
composer install rootinc/faker-bonus --dev
```
## Usage
We can add new Providers directly to the Faker instance before we use it:
### Basic Usage
```php
hashtag;
```
#### Specific Provider/s
```php
addProvider(new Provider\Hashtag($faker));
//...
// Add more Providers
//...
// Use Faker
$faker->hashtag;
```
### Laravel Usage
We can have Providers/Formatters added to all instances of `Faker\Generator` by updating our `AppServiceProvier` as follows:
#### All Providers
app/Providers/AppServiceProvider.php
```php
app->extend(Generator::class, function ($generator) {
// Add Providers to the Faker\Generator class
ProviderCollectionHelper::addAllProvidersTo($generator);
// Return modified Faker\Generator
return $generator;
});
//...
}
```
## Formatters
### Hashtag
Build some fun hashtags.
#### Definition
```php
$faker->hashtag($includeTag = true)
```
#### Usage
```php
$faker->hashtag // '#this_is_fun'
$faker->hashtag(false) // 'this_is_fun'
```
### Mention
Builds handle-ish mentions.
#### Definition
```php
$faker->mention($includeAt = true)
```
#### Usage
```php
$faker->mention // '@bartoletti.barbara'
$faker->mention(false) // 'bartoletti.barbara'
```
### Tweet Text
Create tweet-like text.
#### Definition
```php
$faker->tweetText($nbParagraphs = 1, $includeEmoji = true)
```
#### Usage
```php
$faker->tweetText // '@BSCHADEN The a my were anchors for consider that one man perfectly. 😀 #EXPLOIT_CUTTINGEDGE_EYEBALLS'
$faker->tweetText(2) // '@BSCHADEN The a my were anchors for consider that one man perfectly.\n\n Created, rung and over flows let four it lane.😀 #EXPLOIT_CUTTINGEDGE_EYEBALLS'
$faker->tweetText(3, false) // '@BSCHADEN The a my were anchors for consider that one man perfectly.\n\n Created, rung and over flows let four it lane.\n\n Created, rung and over flows let four it lane. #EXPLOIT_CUTTINGEDGE_EYEBALLS'
```
## Testing
```bash
composer install
vendor/bin/phpunit
```
## Acknowledgements
- Influenced by: [mbezhanov/faker-provider-collection](https://github.com/mbezhanov/faker-provider-collection)