Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
johnykvsky committed Dec 24, 2024
1 parent b543ba5 commit 68b8a72
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Since `--repeat` is still missing in PHPUnit [here](https://github.com/johnykvsk

# TODO (ideas, not promises)

* ... nothing at the moment
* clear only given provider on `addDefinition`?

[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/johnykvsky/dummygenerator.svg?style=flat-square
Expand Down
14 changes: 13 additions & 1 deletion docs/howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ In this example two things happened:

### How can I use language-based definitions

Other way to work with localized extensions is to load them all and use by hand-picking:
Other way to work with localised extensions is to load them all and use by hand-picking:

```php
$container = DefinitionContainerBuilder::default();
Expand All @@ -29,6 +29,18 @@ but this way we skip `__call` in `DummyGenerator` so it won't work with any othe

**Beware**, you need to pay attention to one thing: naming. Magic method `__call` checks if requested method (like `firstName`) exists in any extension. It checks them one by one, in order of adding. So if you have by some reason 2 extensions that has same method (like `getName()` in both of them) and you run `$generator->getName()` it will execute `getName()` in extension that was added earlier to container.

### How can I change definition on the fly

It can be done like this:

```php
$generator->firstName(); // will generate i.e. "Harry"
$generator->addDefinition(PersonExtensionInterface::class, ElvesPerson::class);
$generator->firstName(); // will generate i.e. "Fingolfin"
```

**Beware**, this will clear internal cache for all extensions, so they will be resolved again. Not a big deal, but worth keeping in mind.

### How can I use different strategy

If we want to use different strategy, like uniqueness:
Expand Down
16 changes: 4 additions & 12 deletions docs/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ If you like, you can skip all definitions included with `DummyGenerator` and jus
$generator = new DummyGenerator(new DefinitionContainer(['my_own_item' => new MyOwnItem()]));
```

## Strategy

Now that we know what definitions are, let's move to second parameter - Strategy. Strategy is used on generated data to validate it according to our needs. `DummyGenerator` has build in 4 strategies:

* Simple - default one, just generates data
Expand Down Expand Up @@ -60,7 +62,7 @@ Container builder allows to load predefined sets of extensions. You can choose b

Just pass any of them to `DummyGenerator`.

Available packs are:
Extensions available in each pack:

* Base: Coordinates, Country, DateTime, Hash, Language, Lorem, Number
* Default, all from Base plus: Internet, Person
Expand Down Expand Up @@ -97,17 +99,7 @@ No problem, just try this:
echo $generator->boo('School'); // gives 'School is a crap!'
```

But what if I want to add/replace some definition "on the fly"? It can be done like this:

```php
$generator->firstName(); // will generate i.e. "Harry"
$generator->addDefinition(PersonExtensionInterface::class, ElvesPerson::class);
$generator->firstName(); // will generate i.e. "Fingolfin"
```

**beware** - this will clear internal cache for all extensions, so each call will resolve extensions classes. Not a big deal, but worth keeping in mind.

## Text
## Text Extension

Text extension is a bit different for one reason - it uses external `.txt` file as source to large text. By default, it's in `resources/en_US.txt` but you can either:

Expand Down

0 comments on commit 68b8a72

Please sign in to comment.