1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* Copyright (C) |
6
|
|
|
* Nathan Boiron <[email protected]> |
7
|
|
|
* Romain Canon <[email protected]> |
8
|
|
|
* |
9
|
|
|
* This file is part of the TYPO3 NotiZ project. |
10
|
|
|
* It is free software; you can redistribute it and/or modify it |
11
|
|
|
* under the terms of the GNU General Public License, either |
12
|
|
|
* version 3 of the License, or any later version. |
13
|
|
|
* |
14
|
|
|
* For the full copyright and license information, see: |
15
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace CuyZ\Notiz\Domain\Channel\Log; |
19
|
|
|
|
20
|
|
|
use CuyZ\Notiz\Core\Channel\AbstractChannel; |
21
|
|
|
use CuyZ\Notiz\Domain\Notification\Log\Application\EntityLog\Service\EntityLogMessageBuilder; |
22
|
|
|
use CuyZ\Notiz\Domain\Notification\Log\LogNotification; |
23
|
|
|
use Psr\Log\LoggerInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* This channel is meant to send logs using a PSR-3 logger. |
27
|
|
|
* |
28
|
|
|
* @link http://www.php-fig.org/psr/psr-3/ |
29
|
|
|
* |
30
|
|
|
* To implement a custom logger, you need to extend this class and |
31
|
|
|
* implement `getLoggerInstance()`. |
32
|
|
|
*/ |
33
|
|
|
abstract class LogChannel extends AbstractChannel |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
protected static $supportedNotifications = [ |
39
|
|
|
LogNotification::class, |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var EntityLogMessageBuilder |
44
|
|
|
*/ |
45
|
|
|
protected $messageBuilder; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var LogNotification |
49
|
|
|
*/ |
50
|
|
|
protected $notification; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Manual dependency injection. |
54
|
|
|
*/ |
55
|
|
|
final protected function initialize() |
56
|
|
|
{ |
57
|
|
|
$this->messageBuilder = $this->objectManager->get( |
58
|
|
|
EntityLogMessageBuilder::class, |
59
|
|
|
$this->payload |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$this->notification = $this->payload->getNotification(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* You must implement this method and return an instance of a PSR-3 logger. |
67
|
|
|
* |
68
|
|
|
* @return LoggerInterface |
69
|
|
|
*/ |
70
|
|
|
abstract protected function getLoggerInstance(): LoggerInterface; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* The logging itself is done here using the provided logger. |
74
|
|
|
*/ |
75
|
|
|
final protected function process() |
76
|
|
|
{ |
77
|
|
|
$logger = $this->getLoggerInstance(); |
78
|
|
|
|
79
|
|
|
$message = $this->messageBuilder->getMessage(); |
80
|
|
|
$level = $this->notification->getLevel(); |
81
|
|
|
|
82
|
|
|
$logger->log($level, $message); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|