1
|
|
|
<?php /** MicroEmailDriver */ |
2
|
|
|
|
3
|
|
|
namespace Micro\Logger\Driver; |
4
|
|
|
|
5
|
|
|
use Micro\Base\IContainer; |
6
|
|
|
use Micro\Mail\Message; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* EmailDriver logger class file. |
10
|
|
|
* |
11
|
|
|
* Sender email for logger |
12
|
|
|
* |
13
|
|
|
* @author Oleg Lunegov <[email protected]> |
14
|
|
|
* @link https://github.com/linpax/microphp-framework |
15
|
|
|
* @copyright Copyright © 2013 Oleg Lunegov |
16
|
|
|
* @license /LICENSE |
17
|
|
|
* @package Micro |
18
|
|
|
* @subpackage Logger\Driver |
19
|
|
|
* @version 1.0 |
20
|
|
|
* @since 1.0 |
21
|
|
|
*/ |
22
|
|
|
class EmailDriver extends LoggerDriver |
23
|
|
|
{ |
24
|
|
|
/** @var string $from email for sender attribute */ |
25
|
|
|
private $from; |
26
|
|
|
/** @var string $type message attribute */ |
27
|
|
|
private $type = 'text/plain'; |
28
|
|
|
/** @var string $to message recipient */ |
29
|
|
|
private $to; |
30
|
|
|
/** @var string $subject message theme */ |
31
|
|
|
private $subject; |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Constructor is a initialize logger |
36
|
|
|
* |
37
|
|
|
* @access public |
38
|
|
|
* |
39
|
|
|
* @param IContainer $container Container |
40
|
|
|
* @param array $params configuration params |
41
|
|
|
* |
42
|
|
|
* @throws \Micro\Base\Exception |
43
|
|
|
* @result void |
44
|
|
|
*/ |
45
|
|
|
public function __construct(IContainer $container, array $params = []) |
46
|
|
|
{ |
47
|
|
|
parent::__construct($container, $params); |
48
|
|
|
|
49
|
|
|
$this->from = !empty($params['from']) ? $params['from'] : getenv('SERVER_ADMIN'); |
50
|
|
|
$this->to = !empty($params['to']) ? $params['to'] : $this->from; |
51
|
|
|
$this->subject = $params['subject'] ?: getenv('SERVER_NAME').' log message'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Send message in log |
56
|
|
|
* |
57
|
|
|
* @access public |
58
|
|
|
* |
59
|
|
|
* @param integer $level level number |
60
|
|
|
* @param string $message message to write |
61
|
|
|
* |
62
|
|
|
* @result void |
63
|
|
|
* @throws \Micro\Base\Exception |
64
|
|
|
*/ |
65
|
|
|
public function sendMessage($level, $message) |
66
|
|
|
{ |
67
|
|
|
$mail = new Message($this->from); |
68
|
|
|
|
69
|
|
|
$mail->setTo($this->to); |
70
|
|
|
$mail->setText(ucfirst($level).': '.$message, $this->type); |
71
|
|
|
|
72
|
|
|
$this->container->mail->send($mail); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: