| 1 | <?php |
||
| 25 | abstract class HandlerAbstract implements FormatterAwareInterface |
||
| 26 | { |
||
| 27 | use FormatterAwareTrait; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param FormatterInterface $formatter |
||
| 31 | */ |
||
| 32 | public function __construct(?FormatterInterface $formatter = NULL) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Destructor |
||
| 39 | */ |
||
| 40 | public function __destruct() |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param LogEntryInterface $entry |
||
| 47 | */ |
||
| 48 | public function __invoke(LogEntryInterface $entry) |
||
| 49 | { |
||
| 50 | if ($this->isHandling($entry)) { |
||
| 51 | $this->write($entry); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Close the handler if wanted |
||
| 57 | */ |
||
| 58 | protected function close() |
||
| 59 | { |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Is this handler handling this log ? |
||
| 64 | * |
||
| 65 | * @param LogEntryInterface $entry |
||
| 66 | * @return bool |
||
| 67 | */ |
||
| 68 | protected function isHandling(LogEntryInterface $entry): bool |
||
| 69 | { |
||
| 70 | return $entry ? TRUE : TRUE; |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Write to handler's device |
||
| 75 | * |
||
| 76 | * @param LogEntryInterface $entry |
||
| 77 | */ |
||
| 78 | abstract protected function write(LogEntryInterface $entry); |
||
| 79 | } |