1 | <?php namespace Sofa\Revisionable\Laravel; |
||
7 | class DbLogger implements Logger |
||
8 | { |
||
9 | /** |
||
10 | * Custom database connection. |
||
11 | * |
||
12 | * @var \Illuminate\Database\ConnectionInterface |
||
13 | */ |
||
14 | protected $connection; |
||
15 | |||
16 | /** |
||
17 | * Default database connection. |
||
18 | * |
||
19 | * @var \Illuminate\Database\ConnectionInterface |
||
20 | */ |
||
21 | protected $defaultConnection; |
||
22 | |||
23 | /** |
||
24 | * Revisions table name. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $table; |
||
29 | |||
30 | /** |
||
31 | * Create a new DbLogger. |
||
32 | * |
||
33 | * @param \Illuminate\Database\ConnectionInterface $connection |
||
34 | * @param string $table |
||
35 | */ |
||
36 | public function __construct(ConnectionInterface $connection, $table) |
||
37 | { |
||
38 | $this->defaultConnection = $connection; |
||
39 | $this->table = $table; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Log data revisions in the db. |
||
44 | * |
||
45 | * @param string $action |
||
46 | * @param string $table |
||
47 | * @param int $id |
||
48 | * @param array $old |
||
49 | * @param array $new |
||
50 | * @param string $user |
||
51 | * @return void |
||
52 | */ |
||
53 | public function revisionLog($action, $table, $id, array $old = [], array $new = [], $user = null) |
||
75 | |||
76 | /** |
||
77 | * Set custom connection for the next log. |
||
78 | * |
||
79 | * @param \Illuminate\Database\ConnectionInterface $connection |
||
80 | * @return static |
||
81 | */ |
||
82 | public function on(ConnectionInterface $connection) |
||
83 | { |
||
84 | $this->connection = $connection; |
||
85 | |||
86 | return $this; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Translate provided user to appropriate string. |
||
91 | * |
||
92 | * @param mixed $user |
||
93 | * @return string |
||
94 | */ |
||
95 | protected function parseUser($user) |
||
99 | |||
100 | /** |
||
101 | * Return current connection instance to use for next log. |
||
102 | * |
||
103 | * @return \Illuminate\Database\ConnectionInterface |
||
104 | */ |
||
105 | protected function getCurrentConnection() |
||
109 | |||
110 | /** |
||
111 | * Reset custom connection. |
||
112 | * |
||
113 | * @return void |
||
114 | */ |
||
115 | protected function resetConnection() |
||
119 | |||
120 | /** |
||
121 | * Get Server variable. |
||
122 | * |
||
123 | * @param string $key |
||
124 | * @param mixed $default |
||
125 | * @return string|array |
||
126 | */ |
||
127 | protected function getFromServer($key, $default = null) |
||
131 | } |
||
132 |