nur-sery/nur_src/mapper/item/LoggerConsumer.php

37 lines
806 B
PHP

<?php
namespace nur\mapper\item;
use nur\A;
use nur\mapper\base\Consumer;
use nur\msg;
class LoggerConsumer extends Consumer {
function section(string $title) {
msg::section($title);
}
static function to_string($item): string {
if (A::is_assoc($item)) {
$parts = [];
foreach ($item as $key => $part) {
$parts[] = "$key => ".self::to_string($part);
}
return "{ ".implode(", ", $parts)." }";
} elseif (A::is_seq($item)) {
$parts = [];
foreach ($item as $key => $part) {
$parts[] = self::to_string($part);
}
return implode(", ", $parts);
} elseif (is_string($item)) {
return $item;
} else {
return var_export($item, true);
}
}
function cook($item) {
msg::info(self::to_string($item));
}
}