vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php line 35

Open in your IDE?
  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 the Handler structure, including processors and formatters
  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.  * @phpstan-import-type LevelName from \Monolog\Logger
  20.  * @phpstan-import-type Level from \Monolog\Logger
  21.  * @phpstan-import-type Record from \Monolog\Logger
  22.  * @phpstan-type FormattedRecord array{message: string, context: mixed[], level: Level, level_name: LevelName, channel: string, datetime: \DateTimeImmutable, extra: mixed[], formatted: mixed}
  23.  */
  24. abstract class AbstractProcessingHandler extends AbstractHandler implements ProcessableHandlerInterfaceFormattableHandlerInterface
  25. {
  26.     use ProcessableHandlerTrait;
  27.     use FormattableHandlerTrait;
  28.     /**
  29.      * {@inheritDoc}
  30.      */
  31.     public function handle(array $record): bool
  32.     {
  33.         if (!$this->isHandling($record)) {
  34.             return false;
  35.         }
  36.         if ($this->processors) {
  37.             /** @var Record $record */
  38.             $record $this->processRecord($record);
  39.         }
  40.         $record['formatted'] = $this->getFormatter()->format($record);
  41.         $this->write($record);
  42.         return false === $this->bubble;
  43.     }
  44.     /**
  45.      * Writes the record down to the log of the implementing handler
  46.      *
  47.      * @phpstan-param FormattedRecord $record
  48.      */
  49.     abstract protected function write(array $record): void;
  50.     /**
  51.      * @return void
  52.      */
  53.     public function reset()
  54.     {
  55.         parent::reset();
  56.         $this->resetProcessors();
  57.     }
  58. }