Skip to content

Feature Request: Allow custom Generator class in MakerInterface #1567

Open
@serotoninja

Description

@serotoninja

I would like to propose an enhancement to the symfony/maker-bundle to allow the use of a custom Generator class in the Makers that implement the MakerInterface. This change would provide greater flexibility in creating classes in the desired namespaces and paths.

Currently, the MakerInterface defines the generate method as follows:

public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator);

In this setup, the Generator class is tightly coupled with AutoloaderUtil, limiting customization options for generating files in specific namespaces and paths.

Proposed Change:

I suggest modifying the MakerInterface to accept a GeneratorInterface instead of a Generator. This would allow developers to implement their own Generator class that fits their specific needs.

The new MakerInterface would look like this:

interface MakerInterface
{
    //...
    public function generate(InputInterface $input, ConsoleStyle $io, GeneratorInterface $generator);
}

Benefits:

  • Flexibility: Developers can create and use their own Generator implementations to generate files in customized paths and namespaces.
  • Decoupling: Reduces dependency on AutoloaderUtil, making the codebase more modular and easier to maintain.
  • Extensibility: Encourages the creation of more complex and tailored file generation logic without modifying the core bundle.

Implementation Considerations:

  • Introduce a GeneratorInterface that Generator implements.
  • Update the existing Maker classes to use the new GeneratorInterface.
  • Ensure backward compatibility for existing makers by providing a default implementation of the GeneratorInterface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions