setResponseGenerator(function($error, $object) { $message = substr($error['message'], 0, strpos($error['message'], ' in /')); $response = (new Response(500))->withHeader('Content-Type', 'text/plain'); $response->getBody()->write("Error in implementation of <".$object->getId()."> at revision " . $object->getProperty(ObjectRetriever::REVISION_PROPERTY)->getValue() . ":\n".$message); return $response; }); } public function addMapping($filename, Node $object) { $this->classMap[realpath($filename)] = $object; } public function setResponseGenerator(callable $responseGenerator) { $this->responseGenerator = $responseGenerator; } public function getErrorResponse() { $error = error_get_last(); if ($error !== null && in_array($error['type'], [ E_ERROR, E_COMPILE_ERROR ]) && isset($this->classMap[$error['file']])) { $response = call_user_func($this->responseGenerator, $error, $this->classMap[$error['file']]); (new ResponseEmitter())->emit($response); } } }