<?php
// ApiPlainTextErrorRenderer.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Exception;use Slim\Exception\HttpException;use Slim\Interfaces\ErrorRendererInterface;use Throwable;class ApiPlainTextErrorRenderer implements ErrorRendererInterface{private int $m_debugTrace;public function __construct(){$this->m_debugTrace=0;}public function __invoke(Throwable $exception,bool $displayErrorDetails):string{$result='Code '.$exception->getCode().': '.$exception->getMessage();if(method_exists($exception,'getDescription')&&!empty($exception->getDescription())){$result.=' ('.substr($exception->getDescription(),0,512).')';}$result.=sprintf(", Type: %s",get_class($exception));$file=$exception->getFile();$line=$exception->getLine();if($file!==null){$result.=sprintf("\nFile: %s",$file);if($line!==null)$result.=sprintf("::%s",$line);}if($this->m_debugTrace>0&&$exception->getCode()>=500){$result.=" \nTrace:\n";$trace=$exception->getTraceAsString();if($this->m_debugTrace==1){$traceArray=explode("\n",$trace);for($i=3;$i<100;$i++){if(isset($traceArray[$i]))unset($traceArray[$i]);else break;}$trace=implode("\n",$traceArray);}if($trace!==null){$result.=$trace;}}return $result;}public function setDebugTrace($trace):void{$this->m_debugTrace=$trace;}}