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

Making Faker\Generator's accessable from outside. #186

Closed
h4cc opened this issue Mar 6, 2015 · 9 comments
Closed

Making Faker\Generator's accessable from outside. #186

h4cc opened this issue Mar 6, 2015 · 9 comments
Labels
Milestone

Comments

@h4cc
Copy link
Contributor

h4cc commented Mar 6, 2015

Currently, the Faker Generators are enclosed inside the loaders:
https://github.com/nelmio/alice/blob/1.x/src/Nelmio/Alice/Loader/Base.php#L461

Accessing the Generators from the outside would be useful to be abled to create more Faker Provider that extend Faker\Provider\Base, because that needs a generator to build up on: https://github.com/fzaninotto/Faker/blob/master/src/Faker/Provider/Base.php#L24

Simple Example:

class ExtendedAddressProvider extends Faker\Provider\Address {
    protected static $cityFormatsCool = array(
        '{{firstName}}{{citySuffix}} is cool',
    );
    public function cityWithCoolNames()
    {
        $format = static::randomElement(static::$cityFormats);

        return $this->generator->parse($format);
    }
}

Such a provider will need a Generator in its constructor, but these are not accessable outside the loaders till now.
Maybe this could be a change for 2.0?

@gnat42
Copy link
Contributor

gnat42 commented Mar 13, 2015

This would be very helpful indeed

@Seldaek Seldaek added this to the 2.0 milestone Mar 15, 2015
@Seldaek
Copy link
Member

Seldaek commented Mar 15, 2015

Sounds good to me, not sure how this code looks in the current master/2.0-dev, but if you see a way to make an improvement there please send a PR :)

@theofidry
Copy link
Member

+1 would be great! @h4cc have you any plan to do it soon?

@h4cc
Copy link
Contributor Author

h4cc commented May 29, 2015

@theofidry No plan here yet ...

@theofidry
Copy link
Member

@h4cc erf a pity :( I would be great not to have to override the load method just for this line.

@theofidry
Copy link
Member

Kind of old post so I have lost a little bit sight of what needs to be changed, but if we make the Nelmio\Alice\Loader\Base::getGenerator() public instead of private would solves the problem?

@theofidry
Copy link
Member

Any opinion on this @Seldaek and @h4cc? I can provide a PR to solve this issue but I would like to have your opinion first.

@Seldaek
Copy link
Member

Seldaek commented Jun 15, 2015

Sounds ok to me but would be good to have @tshelburne's opinion as he's more aware of the 2.0 design.

@theofidry
Copy link
Member

theofidry commented Jul 12, 2016

As in real life it is fairly rare to have to access to a faker instance (most of providers have static methods) and considering it's a fairly old issue and nobody really wants to dig into this again, I'll be closing this one. If it is still a problem and are willing to look into it, feel free to open a new issue for it. Note that it is plan to fix it in v3.

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

No branches or pull requests

4 participants