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

AuthLoggingEventHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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