emailConfiguration = $emailConfiguration; $this->callable = $callable; $this->mailer = $mailer; } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface { $response = $handler->handle($request); if ( $response->getStatusCode() === 500 ) { $this->mailer->setTo('dave.mcnicoll@cslsj.qc.ca'); $this->mailer->setFrom(['test@johndoe.com' => 'John Doe']); $bugReport = $response->getBody()->__toString(); if ( false === ( $this->mailer->send(error_get_last()['message'], $bugReport, true) ) ) { error_log("Impossile to send an email bug report from " . static::class); } return $this->callable->call($this); } return $response; } }