How could software like “bake” detect, which parts should be updated and which shouldn’t?
I don’t really know, well, maybe detect some stuff based on conventions?
I don’t know if afterSave() can be generated automagically anywhere in bake?
If not, I think CakePHP could be able to load/overwrite methods in some other file.
like for example Model/Extension/UsersTableExtension.php (please don’t hate if I made mistakes, it’s just a quick mockup):
<?php
namespace App\Model\Table;
// Just an example, the Devs should come up with the convention n such
class UsersTableExtension extends UsersTable {
public function afterSave(Event $event, EntityInterface $entity, \ArrayObject $options) {
// do stuff
}
}
Then bake doesn’t have to do anything in the UsersTableExtension.php, so it doesn’t need to be overwritten.
afterSave() is obviously just one example this could be used for.
Basically, we take all the extending stuff (like afterSave(), beforeDelete(), beforeFind() etc.) and put it somewhere else.
CakePHP will then load up the UsersTable.php and see if there’s a UsersTableExtenstion.php.
If so, it will load and overwrite this stuff in UsersTable.php.
This way, bake can overwrite the model itself (like the initialize(), validationDefault() etc.), but won’t overwrite the other stuff like afterSave().
And if somebody wants to add something to let’s say the initialize() function, he/she could just do it the same way as normal, using the parent::initialize() method.
I don’t know how feasible this is as I haven’t dived that deep into CakePHP yet, but I think this could be done.
EDIT: I’ll actually take this idea to the git repo to start a discussion about this over there