1
votes

is there a way to override Doctrines EntityRepositoryGenerator & EntityGenerator in Symfony2? Due to some Coding Guidlines i would like to modify the default Template used, when Entities & Repository Classes are generated via console.

I tried to place my own classes with the modified Code in app\Resources\doctrine\orm\lib\Doctrine\ORM\Tools but this only seems to work with Ressource Files like Twig Templates, JS etc.

Since the EntityRepositoryGenerator & EntityGenerator aren't Controllers the aproach described in http://symfony.com/doc/current/cookbook/bundles/inheritance.html won't work either?

Do you have any ideas how to achieve my goal? Thanks in advance!

1

1 Answers

1
votes

Unfortunately, the Doctrine entity generator dependency is hardcoded, and its instance is initialised in base DoctrineCommand class.

You could implement your own command that would construct the generator you need, and then use bundle inheritance to replace the base Doctrine command with your implementation. On how to do this, see the documentation and this SO question.

Implementing a new generator should be easy if you start with Doctrine\ORM\Tools\EntityGenerator as a template.