fix/add-venta (#44)

FIXES:
 - cast Comuna.id to int in Propietario
 - Inmobiliaria without tipoSociedad not loading descripcion

Log exception processor
Get Money values when stored as 0

Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl>
Reviewed-on: #44
This commit is contained in:
2025-10-03 12:13:02 -03:00
parent a668b6b7be
commit b0267320a1
11 changed files with 85 additions and 17 deletions

View File

@ -0,0 +1,68 @@
<?php
namespace Incoviba\Common\Implement\Log\Processor;
use Throwable;
use Monolog\LogRecord;
use Monolog\Processor\ProcessorInterface;
class Exception implements ProcessorInterface
{
public function __invoke(LogRecord $record): LogRecord
{
$context = $record->context;
$changed = false;
array_walk_recursive($context, function (&$item) use (&$changed) {
if (is_a($item, Throwable::class)) {
$item = $this->processException($item);
$changed = true;
}
});
if ($changed) {
$new_record = new LogRecord(
$record->datetime,
$record->channel,
$record->level,
$record->message,
$context,
$record->extra
);
$record = $new_record;
}
if (is_a($record->message, Throwable::class)) {
$exception = $record->message;
$output = $this->processException($exception);
$message = $output['message'];
if (array_key_exists('exception', $context)) {
$context['other_exception'] = $context['exception'];
}
$context['exception'] = $output;
$new_record = new LogRecord(
$record->datetime,
$record->channel,
$record->level,
$message,
$context,
$record->extra
);
$record = $new_record;
}
return $record;
}
protected function processException(Throwable $exception): array
{
$output = [
'class' => get_class($exception),
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTraceAsString(),
];
if ($exception->getPrevious() !== null) {
$output['previous'] = $this->processException($exception);
}
return $output;
}
}