Coder Social home page Coder Social logo

Comments (4)

h4cc avatar h4cc commented on August 21, 2024

I think i found what you were trying to do:

Did you try to add a Provider from Faker directly? Like:

services:
    your.faker.provider:
        class: Faker\Provider\DateTime
        tags:
            -  { name: h4cc_alice_fixtures.provider }

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:

services:
    provider.dependency:
        class: ProviderDependency
    provider:
        class: Provider
        arguments: [@provider.dependency]
        tags:
            -  { name: h4cc_alice_fixtures.provider }

from alicefixturesbundle.

nass600 avatar nass600 commented on August 21, 2024

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 @faker.generator service as argument.

My question is:
Should not this bundle take care of registering the needed Faker services taking into account that Faker is a dependency of Nelmio/Alice or I have to register as a service the dependencies of my dependencies

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

from alicefixturesbundle.

h4cc avatar h4cc commented on August 21, 2024

Because every Faker provider needs the @faker.generator service as argument.

This is not correct. Any class can be faker provider, it does not need to extend Faker\Provider\Base.
So its not the responsibility of this bundle to provide services regarding Faker.

But in the end it would be helpful and convenient to provide such a service like Faker\Generator, if it would not depend from the given locale Faker\Factory::create($locale = self::DEFAULT_LOCALE). Currently, all the Faker Generators are managed inside Alice, as can be seen here: https://github.com/nelmio/alice/blob/1.x/src/Nelmio/Alice/Loader/Base.php#L461
There is no way to access these Generators from the outside.

from alicefixturesbundle.

h4cc avatar h4cc commented on August 21, 2024

I created a issue at nelmio/alice for a access to these generators: nelmio/alice#186

from alicefixturesbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.