Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
factory.php
1<?php
2
4
8
9class Factory
10{
11 private static array $instance = [];
12
13 public static function getState(int $userId): CounterState
14 {
15 if (
16 !self::$instance
17 || !array_key_exists($userId, self::$instance)
18 )
19 {
20 $loader = new Counter\Loader($userId);
21
22 if (self::useInMemoryState())
23 {
24 self::$instance[$userId] = new InMemory($userId, $loader);
25 }
26 elseif ($loader->getTotalCounters() >= Counter::getGlobalLimit())
27 {
28 // use db directly
29 self::$instance[$userId] = new InDatabase($userId, $loader);
30 }
31 else
32 {
33 // by default
34 self::$instance[$userId] = new InMemory($userId, $loader);
35 }
36 }
37
38 return self::$instance[$userId];
39 }
40
41 public static function reloadState(int $userId)
42 {
43 if (
44 self::$instance
45 && array_key_exists($userId, self::$instance)
46 )
47 {
48 $state = self::$instance[$userId];
49 $state->init();
50 }
51 }
52
53 private static function useInMemoryState(): bool
54 {
55 if (Option::get('socialnetwork', 'sonet_use_in_memory_counter_state', 'null', '-') !== 'null')
56 {
57 return true;
58 }
59
60 return false;
61 }
62}