Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
analytics.php
1<?php
3
4use CBPRuntime;
5
6class Analytics extends \CBPRuntimeService
7{
8 private $logFile;
9
10 public function start(CBPRuntime $runtime = null)
11 {
12 parent::start($runtime);
13
14 if (defined('ANALYTICS_FILENAME') && is_writable(ANALYTICS_FILENAME))
15 {
16 $this->logFile = ANALYTICS_FILENAME;
17 }
18 }
19
23 public function isEnabled()
24 {
25 return (bool) $this->logFile;
26 }
27
28 public function write(array $documentId, $action, $tag)
29 {
30 $date = date('Y-m-d H:i:s');
31 $host = $_SERVER["HTTP_HOST"];
32 $module = 'bizproc:'. $documentId[0];
33
34 $this->writeToFile(
35 $this->prepareFileContent($date, $host, $module, $action, $tag, $documentId[1])
36 );
37 }
38
39 private function prepareFileContent(...$params)
40 {
41 return implode("\t", $params);
42 }
43
44 private function writeToFile($content)
45 {
46 if (!$this->logFile)
47 {
48 return false;
49 }
50
51 if ($content <> '')
52 {
53 ignore_user_abort(true);
54 if ($fp = @fopen($this->logFile, "ab"))
55 {
56 if (flock($fp, LOCK_EX))
57 {
58 @fwrite($fp, $content . PHP_EOL);
59 @fflush($fp);
60 @flock($fp, LOCK_UN);
61 @fclose($fp);
62 }
63 }
64 ignore_user_abort(false);
65 }
66 }
67}
write(array $documentId, $action, $tag)
Definition analytics.php:28
start(CBPRuntime $runtime=null)
Definition analytics.php:10