Skip to content
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

Cannot get generator for custom faker provider #415

Closed
dantleech opened this issue Jul 2, 2016 · 8 comments
Closed

Cannot get generator for custom faker provider #415

dantleech opened this issue Jul 2, 2016 · 8 comments

Comments

@dantleech
Copy link
Contributor

I have created a custom provider, which needs a Faker Generator instance in the constructor.

The documentation says that this can be retrieved from the Nelmio\Alice\Instances\Processor\Methods\Faker class, however the getGenerator method is private.

@theofidry
Copy link
Member

Urg indeed. I remember there was this discussion about it.

A workaround I've used in HautelookAliceBundle is actually having two Faker generators: I just have to make sure they are initialized with the same value which is not very hard.

Another thing is: check you faker provider again. Providers have A LOT of static calls, it's very rare to actually need to inject a faker instance. To my knowledge, there has been only 3 complains about it: me and h4cc in the issue I've linked, because we were making a bundle and that looked like a design flaw and causing problems for registering custom providers, and you. So it's worth double checking before making any actual change to v2.

That said, it's a flaw that will be fixed in v3 for sure.

@dantleech
Copy link
Contributor Author

Well, in my instance I want to use an instance so that I can inject a media manager from which I can extract file names. I guess I could use static methods to randomly select from a pre-defined path (making it a generic file provider).

@dantleech
Copy link
Contributor Author

That said, I am not sure how I can use static methods to provide data? Are you suggesting to use <identity(Namespace\MyProvider::provideSomeData())> ?

@theofidry
Copy link
Member

That said, I am not sure how I can use static methods to provide data? Are you suggesting to use <identity(Namespace\MyProvider::provideSomeData())> ?

No I meant to inject your provider in the loader.

I'm letting you tinkering with it, if opening up a function fix you're problem it's fine by me as long as it doesn't introduce a BC and is not overly hacky. I just want to avoid to do that unless necessary :)

@dantleech
Copy link
Contributor Author

Ah I see. ok, will give that a shot, maybe I don't need to inject the generator.

@theofidry
Copy link
Member

Any luck @dantleech?

@dantleech
Copy link
Contributor Author

Havn't had an opportunity to tackle this yet, but a project I am working
on requires this, so I will get to it :)

On Wed, Jul 06, 2016 at 02:48:11AM -0700, Théo FIDRY wrote:

Any luck [1]@dantleech?


You are receiving this because you were mentioned.
Reply to this email directly, [2]view it on GitHub, or [3]mute the thread.

Reverse link: [4]unknown

References

Visible links

  1. https://github.com/dantleech
  2. Cannot get generator for custom faker provider #415 (comment)
  3. https://github.com/notifications/unsubscribe/AAgZcfbw136DZRZ4yzHu_Q1ECNd3svK4ks5qS3nbgaJpZM4JDuXy
  4. Cannot get generator for custom faker provider #415 (comment)

@theofidry
Copy link
Member

Closing this now. If you still feel the need for it, feel free to open a new issue for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants