An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# faker-bonus

[![Codeship Status for rootinc/faker-bonus](https://app.codeship.com/projects/3d1428a0-3f07-0138-f2a1-0a35e539f0bc/status?branch=master)](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)