Completed
Push — master ( 232c05...19d7ee )
by wen
07:42
created

Factory::web()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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