MailHandler.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  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 Monolog\Handler;
  11. /**
  12. * Base class for all mail handlers
  13. *
  14. * @author Gyula Sallai
  15. */
  16. abstract class MailHandler extends AbstractProcessingHandler
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function handleBatch(array $records)
  22. {
  23. $messages = array();
  24. foreach ($records as $record) {
  25. if ($record['level'] < $this->level) {
  26. continue;
  27. }
  28. $messages[] = $this->processRecord($record);
  29. }
  30. if (!empty($messages)) {
  31. $this->send((string) $this->getFormatter()->formatBatch($messages));
  32. }
  33. }
  34. /**
  35. * Send a mail with the given content
  36. *
  37. * @param string $content
  38. */
  39. abstract protected function send($content);
  40. /**
  41. * {@inheritdoc}
  42. */
  43. protected function write(array $record)
  44. {
  45. $this->send((string) $record['formatted']);
  46. }
  47. }