Improvements
Added callback tasks
Table behaviors and generic model code use the following signature:
/**
* @param \Cake\Event\Event $event Event
* @param \Cake\Datasource\EntityInterface $entity Entity
* @param \ArrayObject $options Options
* @return void
*/
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options)
And as long you only use methods and attributes of the EntityInterface (as contracted here), this is fine.
But in specific Table class code, you usually also access the entities' concrete properties.
Here using this typehint is somewhat a lie. To please IDE and tooling like PHPStan we can at least fix up the doc block, however.
And that is what this task is doing, declaring the concrete entity to be available and used inside.
Inside the concrete PostsTable after running the callbacks
command:
/**
* @param \Cake\Event\Event $event Event
* @param \App\Model\Entity\Post $entity Entity
* @param \ArrayObject $options Options
* @return void
*/
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options)
The tooling now knows to expect the apps' Post entity and its methods/properties to be available.
You can also add your own tasks into the collection to make certain changes for other CakePHP callbacks. See docs for details.