HandlerWrapper.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. use Monolog\Formatter\FormatterInterface;
  12. /**
  13. * This simple wrapper class can be used to extend handlers functionality.
  14. *
  15. * Example: A custom filtering that can be applied to any handler.
  16. *
  17. * Inherit from this class and override handle() like this:
  18. *
  19. * public function handle(array $record)
  20. * {
  21. * if ($record meets certain conditions) {
  22. * return false;
  23. * }
  24. * return $this->handler->handle($record);
  25. * }
  26. *
  27. * @author Alexey Karapetov <alexey@karapetov.com>
  28. */
  29. class HandlerWrapper implements HandlerInterface
  30. {
  31. /**
  32. * @var HandlerInterface
  33. */
  34. protected $handler;
  35. /**
  36. * HandlerWrapper constructor.
  37. * @param HandlerInterface $handler
  38. */
  39. public function __construct(HandlerInterface $handler)
  40. {
  41. $this->handler = $handler;
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function isHandling(array $record)
  47. {
  48. return $this->handler->isHandling($record);
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function handle(array $record)
  54. {
  55. return $this->handler->handle($record);
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public function handleBatch(array $records)
  61. {
  62. return $this->handler->handleBatch($records);
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function pushProcessor($callback)
  68. {
  69. $this->handler->pushProcessor($callback);
  70. return $this;
  71. }
  72. /**
  73. * {@inheritdoc}
  74. */
  75. public function popProcessor()
  76. {
  77. return $this->handler->popProcessor();
  78. }
  79. /**
  80. * {@inheritdoc}
  81. */
  82. public function setFormatter(FormatterInterface $formatter)
  83. {
  84. $this->handler->setFormatter($formatter);
  85. return $this;
  86. }
  87. /**
  88. * {@inheritdoc}
  89. */
  90. public function getFormatter()
  91. {
  92. return $this->handler->getFormatter();
  93. }
  94. }