Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
counterservice.php
1<?php
2
4
10
17{
18 private static $instance;
19 private static $isJobOn = false;
20
24 private function __construct()
25 {
26 $this->enableJob();
27 }
28
32 public static function getInstance(): CounterService
33 {
34 if (!self::$instance)
35 {
36 self::$instance = new self();
37 }
38
39 return self::$instance;
40 }
41
46 public static function addEvent(string $type, array $data): void
47 {
48 self::getInstance()->storeEvent($type, $data);
49 }
50
55 private function storeEvent(string $type, array $data = []): void
56 {
57 $event = new Event($type);
58 $event->setData($data);
59
60 $this->getEventCollection()->push($event);
61 }
62
70 public static function proceedEvents(): void
71 {
73 }
74
78 private function enableJob(): void
79 {
80 if (!self::$isJobOn)
81 {
82 $application = Application::getInstance();
83 $application && $application->addBackgroundJob(
84 [ __CLASS__, 'proceedEvents' ],
85 [],
87 );
88
89 self::$isJobOn = true;
90 }
91 }
92
96 private function getEventCollection(): EventCollection
97 {
99 }
100}