cakephp / bake

The Bake Command Plugin
Other
110 stars 100 forks source link

Bake should support core plugins better #991

Open markstory opened 3 months ago

markstory commented 3 months ago

Description

Bake could be expanded to include behavior for other core plugins. We could enable this behavior in a generic way so that users could use it in any custom templates they may have.

Controller base - actions with plugin logic

When you're using the authorization plugin, all of your controller actions will require a call to authorize(). That is a perfect task for bake to take care of. For example, controller actions could have a block like:

{% if Bake.hasPlugin('Authorization') %}
    $this->Authorize->authorize(${{ singularVar }});
{% endif %}

This would allow plugins to have deeper integration with bake and get people further faster.

We can also use this to generate a simple login form, and beforeFilter method on a UsersController if the Authentication plugin is present. While I would like to be able to modify the Application methods as well, we would need bake to be able to parse and manipulate files. This feels similar to what rector does, but I'm not sure rector was intended to be used this way.

Model bake - Add plugin behaviors

We could also explore giving plugins ways to hook into table generation. For example plugins could receive the table, inspect schema and add additional behaviors. An example usecase would be a Sluggable behavior being added to models with slug in their schema.

ADmad commented 3 months ago

When you're using the authorization plugin, all of your controller actions will require a call to authorize()

I updated my bake templates to do just that recently :)

We could also explore giving plugins ways to hook into table generation.

That would be great, then I wouldn't have to override methods of the ModelCommand as I do now.