diff --git a/README.md b/README.md index 503152e..bf76d89 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/howto.md b/docs/howto.md index 5e3a2dc..1c955ea 100644 --- a/docs/howto.md +++ b/docs/howto.md @@ -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(); @@ -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: diff --git a/docs/quick_start.md b/docs/quick_start.md index 9863635..ace73e1 100644 --- a/docs/quick_start.md +++ b/docs/quick_start.md @@ -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 @@ -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 @@ -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: