1<?php declare(strict_types=1); 2 3/* 4 * This file is part of the Monolog package. 5 * 6 * (c) Jordi Boggiano <j.boggiano@seld.be> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Monolog\Processor; 13 14/** 15 * Adds a tags array into record 16 * 17 * @author Martijn Riemers 18 */ 19class TagProcessor implements ProcessorInterface 20{ 21 /** @var string[] */ 22 private $tags; 23 24 /** 25 * @param string[] $tags 26 */ 27 public function __construct(array $tags = []) 28 { 29 $this->setTags($tags); 30 } 31 32 /** 33 * @param string[] $tags 34 */ 35 public function addTags(array $tags = []): self 36 { 37 $this->tags = array_merge($this->tags, $tags); 38 39 return $this; 40 } 41 42 /** 43 * @param string[] $tags 44 */ 45 public function setTags(array $tags = []): self 46 { 47 $this->tags = $tags; 48 49 return $this; 50 } 51 52 /** 53 * {@inheritDoc} 54 */ 55 public function __invoke(array $record): array 56 { 57 $record['extra']['tags'] = $this->tags; 58 59 return $record; 60 } 61} 62