I am pretty sure I have a circular reference, but I do not know howto solve it.
I have a trait like this:
trait UseCaseValidatableTrait
{
protected function validateParams(array $rules, array $messages = [])
{
// ... do smtg
}
private function _handle(
callable $fn,
array $rules = [],
array $messages = []
): ?JsonResponse
{
try {
$this->validateParams(
count($rules) ? $rules : ($this->rules ?? []),
$messages
);
return $fn(); // <-- here I call function passed
} catch (Exception $e) {
return new JsonResponse([
'message' => $e->getMessage()
], 500);
}
}
}
And I have the class that uses it like this:
class MyCase implements UseCaseInterface
{
use UseCaseValidatableTrait;
public function handle(): JsonResponse
{
return $this->_handle(function () {
// I do something, here, and sometimes I get error for too much memory consumption
return new JsonResponse([]);
});
}
}
Sometimes, for some use cases, I get error:
Allowed memory size of 134217728 bytes exhausted