-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileBehavior.php
44 lines (37 loc) · 1.18 KB
/
FileBehavior.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace mekegi\ArLogger;
use \Yii;
use \CLogger;
class FileBehavior extends Behavior
{
public $filePath = null;
/**
* @since 23.07.13 15:33
* @author Arsen Abdusalamov
* @param string $title
* @param array $diff
*/
protected function logChanges($title, array $diff)
{
if (!is_writable($this->filePath)) {
Yii::log("{$this->filePath} is not writable!!", CLogger::LEVEL_ERROR);
return;
}
$modelName = get_class($this->owner);
$body = "\n==================\n"
. "== $title ==\n"
. date('r') . "\nModel: $modelName\n";
$user = (isset(Yii::app()->user) && Yii::app()->user->id) ? Yii::app()->user->id : null;
if ($this->bactrace) {
$body .= 'bactrace: ' . implode("\n\t", $this->getBackTrace()) . PHP_EOL;
}
$body .= "user: $user\n\t ---\n";
foreach ($diff as $key => $newVal) {
$oldVal = empty($this->_oldAttributes[$key]) ? null : $this->_oldAttributes[$key];
$body .= "\t$key: [$oldVal -> $newVal]\n";
}
$f = fopen($this->filePath, 'a+');
fwrite($f, $body);
fclose($f);
}
}