-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Faker 2.0 design #1807
Comments
My cents: PHP version Tooling
Architecture My suggestion would be to split
For all the other things the The downside actually is that there will be a lot of different libs that should be loaded, however most of the time you use 1 or maybe 2 and that is it. At this point we are always shipping all of them which is totally unneeded. Myself i will probably provide a nl_NL locale since it is easy for me to read and handle but this will not be coupled with the Faker core itself. My first cents, probably much more to come though. So let us know |
Really support the idea of making a core and pluggable locales. An advantage of this architecture will be the possibility to inject custom locale versions and currently unavailable locales. I am happy to provide dv_MV. |
@localheinz i was thinking about how we can handle the locales and seperate packages where the faker core still holds its value. For example if i have a However how are we handling that from the core? Are we going to implement the interface that should be implemented for those? This will keep real mean to the core however there is always a lot of locale specific. Like a random VAT charge and so on, different identification types. I don't think the core should and can hold all of that (brings us in the same troubles). From the other hand, just leaving all of that up to the locale is also not great. This means that there is no real value of the core itself except maybe make it easy for you to load different locales together. But if you are not doing that, why not just load the locale directly in that case? Imo this is not something we should want since it will split it off way too much. What do you think? |
I think one way to go about that a core class is created as single point of entry with methods providing non locale-specific properties e.g Date, Random number, text, etc. Other locale classes extend same class and define their methods. This will mean each locale needs to have specific readme to list available methods and properties. Something like this:
|
I'm OK with these ideas. Another thing to work on is the ability for locale-specific Fakers to use a different charset for the |
@fzaninotto agree! One thing i however did not mention yet is the ORM integration there is. Are we going to keep that or pull that and maybe publish it as a standalone provider? |
I think they should be moved out and managed by the ORM developers. We can't know and master every ORM out there! |
i can help with laravel ORM |
Good to hear @ManojKiranA. Once we have a first beta of the |
Waiting for it 😎 |
Biggest problem I currently have with this library is that the random method/seed is global/singleton (mt_srand mt_rand). It would be amazing if each Faker instance can have its own Seed. Or at least faker should base on 1 randomBytes() or randomInt() method which is easily overridable so an alternative generator (with an instance seed) can be used. psuedo code below:
|
@joelharkes not sure if this is 100% the case but if so i agree. The seed should be isolated for each instance on its own indeed |
Random thoughts, feel free to comment namespace Faker\English;
// general purpose, locale-specific factory
class Factory extends Faker\Core\Factory {
protected static $defaultProviders = [
'address' => Faker\English\Address::class,
'barcode' => Faker\Core\Barcode::class,
'color' => Faker\English\Color::class,
'datetime' => Faker\English\DateTime::class,
'image' => Faker\Core\Image::class,
'internet' => Faker\English\Internet::class,
'lorem' => Faker\Latin\Lorem::class,
'misc' => Faker\English\Miscellaneous::class,
'payment' => Faker\English\Payment::class,
'person' => Faker\English\Person::class,
'phone' => Faker\English\PhoneNumber::class,
'text' => Faker\English\Text::class,
'uuid' => Faker\English\Uuid::class,
];
// the sttic create() method comes from the parent
}
// specialized purpose, locale-specific factory
class EcommerceFactory extends Faker\Core\Factory {
protected static $defaultProviders = [
'address' => Faker\English\Address::class,
'barcode' => Faker\Core\Barcode::class,
'color' => Faker\English\Color::class,
'datetime' => Faker\English\DateTime::class,
'image' => Faker\Core\Image::class,
'lorem' => Faker\Latin\Lorem::class,
'payment' => Faker\English\Payment::class,
'person' => Faker\English\Person::class,
'phone' => Faker\English\PhoneNumber::class,
'text' => Faker\English\Text::class,
];
}
// allowing users to oferride the providers of a particular factory
class MyEcommerceFactory extends Faker\English\EcommerceFactory {
// is it possible in PHP?
protected static $defaultProviders = [
...Faker\English\EcommerceFactory::$defaultProviders,
'image' => My\Image::class
];
// if we cannot do it, let's just do
public static function create() {
return Faker\English\EcommerceFactory::create([
'image' => My\Image::class,
])
}
}
// usage: use localize factory directly
$faker = new Faker\English\Factory::create();
// multi-language support
$englishFaker = new Faker\English\CRMFactory::create();
$frenchFaker = new Faker\French\CRMFactory::create();
$multiFaker = new \Faker\Core\LanguageAggregate($englishFaker, $frnechFaker)
echo $multiFaker->lastName(); // chooses either one of the locales |
There should be a distinction between the "country" and "language". For example: Belgium might format addresses differently than The Netherlands but they (might) speak the same "language". |
@JoshuaLuckers The concept of "locales" solves that problem; you'd have So instead of using the language names in the namespaces (like Thoughts? |
@svenluijten it may not rely on a crystal clear doc with explicite namespace like : 🤷♂️ |
another option is to keep the locale itself as a single segment of the namespace: |
What about the idea of linked data? Eg. generate 1 set of data to be able to get related data fields. Similar as @joelharkes mentioned, but little more extended: $faker->fixed(true);
echo $faker->name;
// Adaline Reichel
echo $faker->firstName;
// Adaline
echo $faker->lastName;
// Reichel
echo $faker->safeEmail;
// [email protected]
// ...
echo $faker->name;
// Adaline Reichel
$faker->next();
echo $faker->name;
// Roscoe Johns |
I like have factories in faker as factory-muffins do, would be great for tests |
I do like the idea of linked data, in fact I came here to suggest the same. When it comes to instance of faker per locale, I don't think that is a good idea. Instead I would suggest to have a main This could be even expanded to create some form of
In this example |
@hubertnnn 's idea looks promising to me |
@hubertnnn i was thinking more like this: $faker = new Faker();
$faker->addLocale(new MyEnglishLocale);
$faker->addLocale(new MyFrenchLocale);
$faker->addLocale(new MyGermanLocale);
$faker->addProvider(new CustomTelcoEcommerceProvider);
$faker->getFirstname(); // Outputs a random firstname from the list of given locales The only concern im having that this would work fine for a given interface spec where the locale implements a certain interface (and ofc the core methods like digits/date and so on). However in some cases there are also methods specific on a locale. For example different kind of person registration types and so on. |
@pimjansen
then you could use the provided faker directly or use a context to narrow the operations:
All the above would be a valid way to call So we would have 2 points to set locale:
|
@hubertnnn yeah that could indeed be an idea ofcourse. We should aim for an as easy as possible usecase. Im pretty sure that the way it works now won't be backwards compatible. So it is very import to do it correct for the users right away |
@pimjansen May I ask about the status of the project so far?! Do you need help on the new design development?! |
The Guesser should be usable from outside and should have a method to get the guessed name instead of an anonymous Closure. Also: The Guesser could have an option for localization. |
Hey all,
Today we discussed that 1.9.0 will be our last minor release version of the 1.x branch. After this no new enhancements will be done and we will start focusing on
Faker 2.0
. To kick off lets have an open discussion with all of you and share our ideas.Best,
Pim
The text was updated successfully, but these errors were encountered: