<?php
// ApiErrorHandler.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Exception;use DI\Container;use DI\DependencyException;use DI\NotFoundException;use Psr\Http\Message\ResponseFactoryInterface;use Slim\Interfaces\CallableResolverInterface;use Slim\Handlers\ErrorHandler;class ApiErrorHandler extends ErrorHandler{private $m_container;public function __construct(CallableResolverInterface $callableResolver,ResponseFactoryInterface $responseFactory,Container $container){$this->m_container=$container;$this->defaultErrorRendererContentType='application/json';$this->defaultErrorRenderer=new ApiJsonErrorRenderer;$this->logErrorRenderer=new ApiPlainTextErrorRenderer;$debugDetailedLog=$this->m_container->get('debug_detailed_log');$this->logErrorRenderer->setDebugTrace($debugDetailedLog);parent::__construct($callableResolver,$responseFactory);}protected function writeToErrorLog():void{$renderer=$this->callableResolver->resolve($this->logErrorRenderer);$error=$renderer($this->exception,$this->logErrorDetails);$this->logError($error);}protected function logError(string $error):void{try{$this->m_container->get('logger')->error($error);}catch(DependencyException $e){}catch(NotFoundException $e){}}}