Skip to content

Ability to decorate *Fixture and *ExampleFactory #21

@igormukhingmailcom

Description

@igormukhingmailcom

TLDR Context
When implementing plugins for Sylius, I usually add fixtures - that way app developer can "in one click" try plugin (without eating time to add some data manually).

Sometime plugins extending core resources (Product, Order, etc) and I believe we should have safe way to extend or even decorate *ExampleFactory for core resources.

Safe means that solution should work even if 2 or more plugins will be installed that make changes to same *ExampleFactory. This can be done with decorators I believe.

But methods at *ExampleFactory and *Factory protected which make that impossible to create safe solutions.

Describe the proposed solution

  1. Replace:
protected function configureResourceNode(ArrayNodeDefinition $resourceNode): void;

with

public function configureResourceNode(ArrayNodeDefinition $resourceNode): void;

at AbstractResourceFixture and related core resources fixtures.

  1. Add ConfigurableExampleFactoryInterface (or DecorableExampleFactoryInterface, not sure about name) - optional
interface ConfigurableExampleFactoryInterface extends ExampleFactoryInterface
{
    public function configureOptions(OptionsResolver $resolver): void;
}
  1. Replace AbstractExampleFactory with:
abstract class AbstractExampleFactory implements ConfigurableExampleFactoryInterface
{
    abstract public function configureOptions(OptionsResolver $resolver): void;
}

Additional context
As far as currently we have some BC breaking changes in this area ("Make FixturesBundle standalone") - I believe this is good time to do proposed change too.

I will make PR - just let me know please to what branch I should base it to.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementMinor issues and PRs improving the current solutions (optimizations, typo fixes, etc.).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions