Keine Beschreibung

AbstractProcessingHandler.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 Handler class providing the Handler structure
  13. *
  14. * Classes extending it should (in most cases) only implement write($record)
  15. *
  16. * @author Jordi Boggiano <j.boggiano@seld.be>
  17. * @author Christophe Coevoet <stof@notk.org>
  18. */
  19. abstract class AbstractProcessingHandler extends AbstractHandler
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function handle(array $record)
  25. {
  26. if (!$this->isHandling($record)) {
  27. return false;
  28. }
  29. $record = $this->processRecord($record);
  30. $record['formatted'] = $this->getFormatter()->format($record);
  31. $this->write($record);
  32. return false === $this->bubble;
  33. }
  34. /**
  35. * Writes the record down to the log of the implementing handler
  36. *
  37. * @param array $record
  38. * @return void
  39. */
  40. abstract protected function write(array $record);
  41. /**
  42. * Processes a record.
  43. *
  44. * @param array $record
  45. * @return array
  46. */
  47. protected function processRecord(array $record)
  48. {
  49. if ($this->processors) {
  50. foreach ($this->processors as $processor) {
  51. $record = call_user_func($processor, $record);
  52. }
  53. }
  54. return $record;
  55. }
  56. }