VarDumperFormatter.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bridge\Monolog\Formatter;
  11. use Monolog\Formatter\FormatterInterface;
  12. use Symfony\Component\VarDumper\Cloner\VarCloner;
  13. /**
  14. * @author Grégoire Pineau <lyrixx@lyrixx.info>
  15. */
  16. class VarDumperFormatter implements FormatterInterface
  17. {
  18. private $cloner;
  19. public function __construct(VarCloner $cloner = null)
  20. {
  21. $this->cloner = $cloner ?: new VarCloner();
  22. }
  23. /**
  24. * {@inheritdoc}
  25. *
  26. * @return mixed
  27. */
  28. public function format(array $record)
  29. {
  30. $record['context'] = $this->cloner->cloneVar($record['context']);
  31. $record['extra'] = $this->cloner->cloneVar($record['extra']);
  32. return $record;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. *
  37. * @return mixed
  38. */
  39. public function formatBatch(array $records)
  40. {
  41. foreach ($records as $k => $record) {
  42. $record[$k] = $this->format($record);
  43. }
  44. return $records;
  45. }
  46. }