PHPackages                             clabonte/faker-config - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. clabonte/faker-config

ActiveLibrary

clabonte/faker-config
=====================

Faker extension to populate entities via a simple JSON configuration file

v1.0(8y ago)0172MITPHP

Since Sep 7Pushed 8y ago2 watchersCompare

[ Source](https://github.com/clabonte/faker-config)[ Packagist](https://packagist.org/packages/clabonte/faker-config)[ RSS](/packages/clabonte-faker-config/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

faker-config
============

[](#faker-config)

FakerConfig is a [Faker](https://github.com/fzaninotto/Faker) extension to populate entities via a simple JSON configuration file.

FakerConfig provides an easy way to configure the format to use when generating data for a given entity/property combination.

[![Build Status](https://camo.githubusercontent.com/7e36a76ded2413eec986352d66f974b69877c97500ad56fde7e273ccc6b558cc/68747470733a2f2f7472617669732d63692e6f72672f636c61626f6e74652f66616b65722d636f6e6669672e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/7e36a76ded2413eec986352d66f974b69877c97500ad56fde7e273ccc6b558cc/68747470733a2f2f7472617669732d63692e6f72672f636c61626f6e74652f66616b65722d636f6e6669672e7376673f6272616e63683d6d6173746572)

With this extension, one can create a simple JSON configuration file to describe how to format various Entities and their properties. FakerConfig will parse Faker's Generator PHPDoc used to identify the list of valid formats that can be used by the configuration file and will validate the configuration file against to to reject any format that won't be understood by Faker

**Table of Contents**

- [Configuration File](#configuration-file)
- [Step 1. Create the ConfigGuesser](#step-1-create-the-configguesser)
- [Step 2. Load the Configuration File](#step-2-load-the-configuration-file)
    - [Alternate Solution: Configure the Guesser Programmatically](#alternate-solution-configure-the-guesser-programmatically)
- [Step 3. Populate Your Entity](#step-3-populate-your-entity)
    - [Populate an Object Entity](#populate-an-object-entity)
    - [Populate an Array Entity](#populate-an-array-entity)

Configuration File
------------------

[](#configuration-file)

The configuration is done via a very simply JSON file that lists out entities to populate as JSON objects ('\*' = wildcard). For each entity, you simply list out the properties you want to populate along with the format to use.

Here is a sample configuration file:

```
{
  "*": {
    "id": "uuid"
  },

  "Book": {
    "id": "isbn10"
  },

  "Entity": {
    "property1": "url",
    "property2": "numberBetween(0,10)"
  },

  "Package\\Entity": {
    "property1": "city",
    "property2": "words(5, true)"
  }
}
```

Sample configuration files are available in the project:

- Simple file: [example-config.json](examples/example-config.json)
- Configuration with class hierarchy: [guesser-object-config.json](tests/fixtures/guesser-object-config.json)

Step 1. Create the ConfigGuesser
--------------------------------

[](#step-1-create-the-configguesser)

The first step consists in creating a ConfigGuesser object with the generator to use:

```
$generator = \Faker\Factory::create();
$guesser = new \FakerConfig\ConfigGuesser($generator);
```

Step 2. Load the Configuration File
-----------------------------------

[](#step-2-load-the-configuration-file)

Then, you need to tell the guesser the list of entities/properties that need to be formatted when populating data.

The easiest way to do so is by loading your JSON configuration file:

```
\FakerConfig\ConfigGuesserLoader::loadFile($guesser, 'path_to_your_config.json');
```

### Alternate Solution: Configure the Guesser Programmatically

[](#alternate-solution-configure-the-guesser-programmatically)

Alternatively, you can also configure the guesser programmatically using the FormatParser:

```
$parser = new \FakerConfig\Parser\FormatParser();
$parser->load($guesser->getGenerator());

// You can use any property defined in the Generator's PhpDoc
$format = $parser->parse("firstName");
$guesser->addFormat('Entity', 'property1', $format);

// Or any method defined in the Generator's PhpDoc
$format = $parser->parse("numberBetween(0,10)");
$guesser->addFormat('Entity', 'property2', $format);

// Wildcard define format to use for a given property for any entity
$format = $parser->parse("uuid");
$guesser->addFormat(\Faker\Guesser\ConfigGuesser::WILDCARD, 'id', $format);

// Specific entity/property format will always take precedence over a wildcard format
$format = $parser->parse("isbn10");
$guesser->addFormat('Book', 'id', $format);
```

Step 3. Populate Your Entity
----------------------------

[](#step-3-populate-your-entity)

Once the ConfigGuesser has been properly configured, you can use it with a populator to fill your entity. FakeConfig provides 2 populators to do so:

- ObjectPopulator: To populate an object entity
- ArrayPopulator: To populate an associative array entity

### Populate an Object Entity

[](#populate-an-object-entity)

The ObjectPopulator can be used to populate any object automatically based on its class hierarchy. The populator will scan the object class and all of its ancestor to identify the list of properties that must be populated and apply the format defined in your configuration.

```
/* Assuming the Book class has the following properties:
   - id
   - property1
   - property2

  And the ConfigGuesser has been configured with the following JSON:
  {
    "Book": {
        "id": "isbn10",
        "property1": "words(5, true)"
    }
  }
 */

// The following would populate the Book object as follow:
// - 'id' = random ISBN
// - 'property1' = random string of 5 words
// - 'property2' = no update

$populator = new \FakerConfig\Populator\ObjectPopulator($generator, $guesser);
$book = new Book();
$populator->populate($book);
```

Populate an Array Entity
------------------------

[](#populate-an-array-entity)

You can also populate any associative array using a similar approach:

```
$array = array(
    'id' => null,
    'property1' => null,
    'property2' => null,
    'property3' => null);

/*
  Assuming the ConfigGuesser has been configured with the following JSON:
  {
    "*": {
      "id": "uuid",
    },
    "Entity": {
        "property1": "name",
        "property2": "numberBetween(0,10)"
     }
  }
 */

// The following would populate the array as an 'Entity' entity as follow:
// - 'id' = random UUID
// - 'property1' = random name
// - 'property2' = random number between 0 and 10
// - 'property3' = no update

$populator = new \FakerConfig\Populator\ArrayPopulator($generator, $guesser);
$populator->populate($array, 'Entity');
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3167d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/622674fabf42ad235895d5b9d7a48b92347f8b7fcd3f20fa42344c83c89facb4?d=identicon)[clabonte](/maintainers/clabonte)

---

Top Contributors

[![clabonte](https://avatars.githubusercontent.com/u/3989686?v=4)](https://github.com/clabonte "clabonte (2 commits)")

---

Tags

fakerfixturesdata

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/clabonte-faker-config/health.svg)

```
[![Health](https://phpackages.com/badges/clabonte-faker-config/health.svg)](https://phpackages.com/packages/clabonte-faker-config)
```

###  Alternatives

[fakerphp/faker

Faker is a PHP library that generates fake data for you.

3.9k358.5M3.5k](/packages/fakerphp-faker)[willdurand/faker-bundle

Put the awesome Faker lib into the DIC and populate your database with fake data.

2751.2M14](/packages/willdurand-faker-bundle)[mbezhanov/faker-provider-collection

A collection of custom providers for the Faker library

2138.6M24](/packages/mbezhanov-faker-provider-collection)[bheller/images-generator

Generator of placeholder images for Faker

573.1M3](/packages/bheller-images-generator)[xefi/faker-php

Faker allows you to generate realistic fake data for your php applications

15116.5k15](/packages/xefi-faker-php)[hydreflab/jedi-faker

Faker extension for Star Wars junkie

1429.5k1](/packages/hydreflab-jedi-faker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
