-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing dependencies when creating custom Faker Providers #42
Comments
I think i found what you were trying to do: Did you try to add a Provider from Faker directly? Like:
These providers do not need to be added manually to faker, they are always available anyway: https://github.com/fzaninotto/Faker/blob/master/src/Faker/Factory.php#L9-20 And if your own provider would need a special dependency, it has to configured like so:
|
That's not what I tried to do. I simply create a new Provider: <?php
namespace AppBundle\DataFixtures\Provider;
use Faker\Provider\Base;
/**
* Class MathProvider
*/
class Math extends Base
{
/**
* Evaluates a math operation
*
* @param string $string
*
* @return mixed
*/
public function math($string)
{
return "whatever"
}
} and register it as a service following the README file (not working for me): parameters:
math.provider.class: AppBundle\DataFixtures\Provider\Math
services:
math.provider:
class: %math.provider.class%
tags:
- { name: h4cc_alice_fixtures.provider } But this way, of course, it is working: parameters:
math.provider.class: AppBundle\DataFixtures\Provider\Math
faker.generator.class: Faker\Factory
services:
faker.generator:
class: %faker.generator.class%
factory: [%faker.generator.class%, create]
math.provider:
class: %math.provider.class%
arguments: [@faker.generator]
tags:
- { name: h4cc_alice_fixtures.provider } Because every Faker provider needs the My question is: If the second one, maybe the documentation should mention that in order to create a Faker provider we need to register the Faker services before but IMO I think the bundle must take care of registering its dependencies services. Thank you |
This is not correct. Any class can be faker provider, it does not need to extend But in the end it would be helpful and convenient to provide such a service like |
I created a issue at nelmio/alice for a access to these generators: nelmio/alice#186 |
Hi there!
Maybe I am missing something but following README instruction for adding new Faker providers lead me to the following error:
Symfony\Component\Debug\Exception\ContextErrorException]
Catchable Fatal Error: Argument 1 passed to Faker\Provider\Base::__construct() must be an instance of Faker\Generator, none given...
Every Faker Provider needs the dependency @faker.generator however this service is not registered by the bundle so if I add it the way:
I get the non existing dependency error.
Any clue?
The text was updated successfully, but these errors were encountered: