* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Monolog\Handler; /** * Helper trait for implementing ProcessableInterface * * @author Jordi Boggiano */ trait ProcessableHandlerTrait { /** * @var callable[] */ protected $processors = []; /** * {@inheritdoc} */ public function pushProcessor(callable $callback): HandlerInterface { array_unshift($this->processors, $callback); return $this; } /** * {@inheritdoc} */ public function popProcessor(): callable { if (!$this->processors) { throw new \LogicException('You tried to pop from an empty processor stack.'); } return array_shift($this->processors); } /** * Processes a record. * * @param array $record * @return array */ protected function processRecord(array $record) { foreach ($this->processors as $processor) { $record = $processor($record); } return $record; } }