Completed
Push — master ( 3f2c58...3eb51e )
by wen
02:00
created

Factory::event()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 2 Features 1
Metric Value
dl 0
loc 20
rs 9.4285
c 2
b 2
f 1
cc 3
eloc 13
nc 2
nop 1
1
<?php
2
3
namespace Sco\ActionLog;
4
5
use Sco\ActionLog\Models\ActionLogModel;
6
7
class Factory
8
{
9
10
    /**
11
     * Logging Action
12
     *
13
     * @param \Sco\ActionLog\LogInfo $info
14
     *
15
     * @return bool
16
     */
17
    public function info(LogInfo $info)
18
    {
19
        $log = new ActionLogModel();
20
21
        if (!$info->getUserId() && !config('actionlog.guest')) {
22
            return false;
23
        }
24
25
        $content = $info->getContent();
26
        $client  = $info->getClient();
27
28
        $log->user_id    = $info->getUserId();
29
        $log->type       = $info->getType();
30
        $log->table_name = $info->getTableName();
31
        $log->content    = is_string($content) ? $content : json_encode($content);
32
        $log->client_ip  = $info->getClientIp();
33
        $log->client     = is_string($client) ? $client : json_encode($client);
34
        $log->save();
35
36
        return true;
37
    }
38
39
40
    public function __call($method, $parameters)
41
    {
42
        return (new ActionLogModel)->$method(...$parameters);
43
    }
44
45
46
    public static function __callStatic($method, $parameters)
47
    {
48
        return (new static)->$method(...$parameters);
49
    }
50
}
51