Handler.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php declare(strict_types=1);
  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 basic close() support as well as handleBatch
  13. *
  14. * @author Jordi Boggiano <j.boggiano@seld.be>
  15. */
  16. abstract class Handler implements HandlerInterface
  17. {
  18. /**
  19. * {@inheritDoc}
  20. */
  21. public function handleBatch(array $records): void
  22. {
  23. foreach ($records as $record) {
  24. $this->handle($record);
  25. }
  26. }
  27. /**
  28. * {@inheritDoc}
  29. */
  30. public function close(): void
  31. {
  32. }
  33. public function __destruct()
  34. {
  35. try {
  36. $this->close();
  37. } catch (\Throwable $e) {
  38. // do nothing
  39. }
  40. }
  41. public function __sleep()
  42. {
  43. $this->close();
  44. $reflClass = new \ReflectionClass($this);
  45. $keys = [];
  46. foreach ($reflClass->getProperties() as $reflProp) {
  47. if (!$reflProp->isStatic()) {
  48. $keys[] = $reflProp->getName();
  49. }
  50. }
  51. return $keys;
  52. }
  53. }