Completed
Push — master ( db079f...ae1003 )
by Thomas
06:44 queued 04:24
created

AuthLoggingEventHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 14 1
1
<?php
2
3
namespace example\components;
4
5
use Tebe\Pvc\Application;
6
use Tebe\Pvc\Event\Event;
7
use Tebe\Pvc\Event\EventHandler;
8
use Tebe\Pvc\Exception\SystemException;
9
10
class AuthLoggingEventHandler implements EventHandler
11
{
12
13
    protected $logFile;
14
15
    /**
16
     * AuthLoggingEventHandler constructor.
17
     * @param string $logFile
18
     */
19
    public function __construct(string $logFile)
20
    {
21
        $this->logFile = $logFile;
22
    }
23
24
    /**
25
     * @param Event $event
26
     * @throws SystemException
27
     */
28
    public function handle(Event $event) : void
29
    {
30
31
        $authData = $event->getInfo();
32
33
        $fields = [
34
                    date('Y-m-d H:i:s'),
35
                    json_encode(Application::instance()->getRequest()->getServerParams()),
36
                    $event->getName(),
37
                    $authData['user'],
38
                    $authData['password']
39
                ];
40
41
        error_log(implode('|', $fields) . "\n", 3, $this->logFile);
42
    }
43
}
44