<?php
class Controller {
protected $wrapped = [];
public function abc($request) {
// did we wrap this yet?
if (! isset($this->wrapped['abc'])) {
// if not, do it now. this will only happen once (unless you clear it out).
$this->wrapped['abc'] = $this->wrap(
function ($request) {
return "abc\n";
}
);
}
// invoke and return.
return $this->wrapped['abc']($request);
}
protected function wrap(callable $inner_controller) {
return function($request) use ($inner_controller) {
// stuff
$response = $inner_controller($request);
// stuff
return $response;
};
}
}
$ctrl = new Controller();
echo $ctrl->abc('the request');