Customizing code generation

Code generator listeners

When beans and DAOs PHP files are generated by TDBM a number of events are triggered. You can hook on these events to add some specific code.

A few possible use cases:

  • change the coding styles of generated beans and DAOs (maybe you don't like PSR2 and want something else?)
  • generate one service per DAO in your favorite DI container (the MoufDiListener class does precisely that)
  • generate a GraphQL schema out of the database model
  • modify the code generated for one particular function
  • dynamically add other generated functions
  • ...

There are 2 interfaces you can implement to react on code generation.

  • Implement GeneratorListenerInterface if you want to get a list of all beans/DAOs generated. This is useful if you want to auto-generate a container for instance
  • Implement CodeGeneratorListenerInterface if you want to alter generated code. For instance, the thecodingmachine/tdbm-graphql package uses this listener to add annotations directly in the beans.

Instances of GeneratorListenerInterface and CodeGeneratorListenerInterface must be referenced in the Configuration object.

Found a typo? Something is wrong in this documentation? Just fork and edit it!