Closed biserantonov closed 3 years ago
I'm not sure I like this. Note that it's not required to use the faker facade, even without this change, you can still use our actual faker proxy object, to get the lazy behaviour.
The faker is just for example. Most often I need to execute some code which will affect several of the attributes definitions, and it's easier to wrap them all in one callback
Hmmm, that is true. I'll sleep on it. :)
Here is one more suitable example:
$fm->define('Image')->setDefinitions(function () use ($faker){
$img = $faker->image();
list($width, $height) = getimagesize($img);
$size = filesize($img);
return [
'path' => $img,
'width' => $width,
'height' => $height,
'size' => $size
];
});
There are situations when I need the definitions to be generated prior to instantiation of the model, so I added the option to provide callback instead of array to setDefinitions() method. The callback is responsible to return an array of attributes definitions. For example we can use a $faker instance instead of the facade and do some calculations in isolated space before returning definitions.