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

Not easy to use outside symfony #175

Open
ktom opened this issue May 18, 2021 · 3 comments
Open

Not easy to use outside symfony #175

ktom opened this issue May 18, 2021 · 3 comments

Comments

@ktom
Copy link

ktom commented May 18, 2021

Hello,

I've been trying to use the lib outside of a symfony project, in a package using doctrine.

Following the basic exemple from the doc i've been trying to do something like

<?php

$files = [
    'path/to/src/fixtures/dummy.yml',
    'path/to/src/fixtures/related_dummy.yml',
];

// $loader = $container->get('fidry_alice_data_fixtures.loader.doctrine');

// => instantiate by hand instead of relying on the container
$loader = new \Fidry\AliceDataFixtures\Loader\PurgerLoader(
    // HUUUGGGE OBJECT GRAPH with classes from
    // \Fidry\AliceDataFixtures\
    // and dozens from \Nelmio\Alice\
)

$objects = $loader->load($files);

I gave up on the huge object graph part :'(

Do you have any exemple of how to use the lib outside of SF or any advice on how I could achieve this ?
Thank you in advance

@theofidry
Copy link
Owner

For nelmio alice there is a native loader which should help out. For this library part though there's not been a need for it yet so you would indeed need to create everything yourself by hand or alternatively register the appropriate services to your container

@ktom
Copy link
Author

ktom commented May 19, 2021

Thanks for the feedback,

I've been checking the native loader and indeed it's a great way to have a pre-configured loader but it's not easy to customize except by extending it.

I've finished recreating the object graph it's more or less 250 lines of code ^^

Would you consider a PR on alice introducing a builder for the loaders, something like:

class LoaderBuilderTest extends TestCase
{
    public function test_it_creates_a_prefconfigured_files_loader()
    {
        $loader = LoaderBuilder::simpleFilesLoader()
            ->getLoader();

        $this->assertInstanceOf(SimpleFilesLoader::class, $loader);
    }

    public function test_it_can_change_property_accessor()
    {
        $loader = LoaderBuilder::simpleFilesLoader()
            ->withPropertyAccessory(new MyProperyAccessor())
            ->getLoader();

        $this->assertInstanceOf(/**  */);
    }
}

I don't know what king of meaningfull tests could be done here as the goal of the builder is to set the internals of the class ...
I'm also open to other suggestions that could help me use the lib outside of symfony

@theofidry
Copy link
Owner

@ktom would it be possible to have more details on what the graph looks like? I don't think you should have much from NelmioAlice as there is a NativeLoader or something equivalent to help out with it.

But otherwise I think it's a tedious task as it would require a native loader for different bridges (ORM, ODM, PHPCR, Eloquent...)

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

No branches or pull requests

2 participants