Skip to content

Commit

Permalink
Document all formatters.
Browse files Browse the repository at this point in the history
Closes fzaninotto#3.
  • Loading branch information
fzaninotto committed Oct 15, 2011
1 parent 264d755 commit ef74dae
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
46 changes: 44 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,49 @@ echo $faker->lorem;
// Ea quaerat et quisquam. Deleniti sunt quam. Adipisci consequatur id in occaecati.
// Et sint et. Ut ducimus quod nemo ab voluptatum.
```
## Formatters

Here is a list of the bundled formatters in the default locale.

### Lorem
* `lorem()` // 'Sapiente sunt omnis. Ut pariatur ad autem ducimus et. Voluptas rem voluptas sint modi dolorem amet.'
* `paragraph()` // 'Sapiente sunt omnis. Ut pariatur ad autem ducimus et. Voluptas rem voluptas sint modi dolorem amet.'
* `paragraphs()` // array($paragraph1, $paragraph2, $paragraph3)
* `sentence()` // 'Lorem ipsum dolor sit amet.'
* `sentences()` // array('Lorem ipsum dolor sit amet.', 'Consectetur adipisicing eli.')
* `word()` // 'Lorem'
* `words()` // array('Lorem', 'ipsum', 'dolor')
### Address
* `address()` // '791 Crist Parks, Sashabury, IL 86039-9874'
* `buildingNumber()` // '791'
* `city()` // 'Sashabury'
* `cityPrefix()` // 'East'
* `citySuffix()` // 'town'
* `country()` // 'Japan'
* `postcode()` // 86039-9874
* `secondaryAddress()` // 'Appt. 350'
* `state()` // 'California'
* `stateAbbr()` // 'CA'
* `streetAddress()` // '791 Crist Parks'
* `streetName()` // 'Crist Parks'
* `streetSuffix()` // 'Avenue'
### Company
* `bs()` // 'integrate extensible convergence'
* `catchPhrase()` // 'Robust full-range hub'
* `company()` // 'Acme Ltd'
* `companySuffix()` // 'Ltd'
### Name
* `firstName()` // 'John'
* `lastName()` // 'Doe'
* `name()` // 'John Doe'
* `prefix()` // 'Mrs.'
* `suffix()` // 'PhD'
### PhoneNumber
* `phoneNumber()` // '555-123-546'

## Providers

As a matter of fact, a `Faker\Generator` alone can't do much generation. It needs `Faker\Provider` objects to delegate the data generation to them. `Faker\Factory` actually creates a `Faker\Generator` bundled with the default providers. Here is what happens under the hood:
As a matter of fact, a `Faker\Generator` alone can't do much generation. It needs `Faker\Provider` objects to delegate the data generation to them. `Faker\Factory::create()` actually creates a `Faker\Generator` bundled with the default providers. Here is what happens under the hood:

```php
<?php
Expand All @@ -50,10 +89,13 @@ Whenever you try to access a property on the `$faker` object, the generator look

That means that you can esily add your own providers to a `Faker\Generator`. Just have a look at the existing providers to see how you can design powerful data generators in no time.

`Faker\Factory` can take a locale as an argument, to return localized data. If no localized provider is found, the factory returns a provider with the default locale.
## Localization

`Faker\Factory` can take a locale as an argument, to return localized data. If no localized provider is found, the factory fallbacks to the default locale.

```php
$faker = Faker\Factory::create('fr_FR'); // create a French faker
echo $faker->name; // 'Jean Dupont'
```

## Real Life Usage
Expand Down
8 changes: 7 additions & 1 deletion test/documentor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@

$generator = Faker\Factory::create();
$documentor = new Faker\Documentor($generator);
print_r($documentor->getFormatters());
?>
<?php foreach ($documentor->getFormatters() as $provider => $formatters): ?>
### `<?php echo $provider ?>`
<?php foreach ($formatters as $formatter => $example): ?>
* <?php echo str_pad('`' . $formatter . '()`', 20) ?><?php if ($example): ?> // <?php echo $example ?> <?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>

0 comments on commit ef74dae

Please sign in to comment.