Does cakephp has an equivalent of onKernelTerminate of symfony?

During lunch we talked about symonfy’s “onKernelTerminate” and I got asked if cakephp has something like that.
I thought afterFilter could be an equivalent, but it’s get executed before the response is sent but after the controller’s action return.
for example if I put this in a controller’s action:

public function index(){
    return $this->getResponse()->withStringBody("[]");
}

the response content will be sent after the afterFilter execution.
So, does cakephp has something like onKernelTerminate?
Without enqueuing the job and run asynchronously
Thanks :smiley:

This does the trick:

public function __destruct(){

but it looks kinda ugly

EDITED to add:
it could be combined with:

public function __destruct(){
   if($this->getRequest()->getParam('action') === 'myweirdaction'){}
}

That’s a beauty XD

Depending on exactly when you want the thing to run, middleware might also be an option.

You have the afterFilter/shutdown event, i think its before the “return” of middlewares.

If you want at the very last i guess a middleware could be better