Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
durationcountbased.php
1<?php
9
11
14
15Loc::loadMessages(__FILE__);
16
22{
24 private $message;
25
27 private $count;
28
36 public static function create(Message\Adapter $message)
37 {
38 return new static($message);
39 }
40
46 public function __construct(Message\Adapter $message)
47 {
48 $this->message = $message;
49 }
50
57 public function getInterval($count)
58 {
59 if (!$count)
60 {
61 return 0;
62 }
63
64 $this->count = $count;
66 $limiter = current($this->getLimiters());
67 if (!$limiter)
68 {
69 return 0;
70 }
71
72 $limit = $limiter->getLimit();
73 if (!$limit)
74 {
75 return 0;
76 }
77
78 $timeouts = $this->getLimitTimeouts($limiter);
79 $unit = $this->getLimitUnit($limiter);
80
81 if ($timeouts)
82 {
83 $count = $this->count % ($limit * $timeouts);
84 }
85 else
86 {
87 $count = $this->count;
88 }
89
90 return ($timeouts * $unit) + ($count * $this->message->getSendDuration());
91 }
92
99 public function getIntervalDefault($count)
100 {
101 $interval = $this->getInterval($count);
102 if ($interval)
103 {
104 return $interval;
105 }
106
107 return ceil(0.01 * $count);
108 }
109
110 protected function getLimitUnit(Transport\iLimiter $limiter)
111 {
112 return Transport\CountLimiter::getUnitInterval($limiter->getUnit());
113 }
114
115 protected function getLimitTimeouts(Transport\iLimiter $limiter)
116 {
117 $count = $this->count;
118 $limit = $limiter->getLimit();
119 $count -= $limit - $limiter->getCurrent();
120 if (!$count || !$limit)
121 {
122 return 0;
123 }
124
125 return intval($count / $limit);
126 }
127
128 protected function getLimiters()
129 {
130 $transport = $this->message->getTransport();
131 if (!$transport)
132 {
133 return array();
134 }
135
136 return $transport->getLimiters($this->message);
137 }
138}
static loadMessages($file)
Definition loc.php:64
static create(Message\Adapter $message)
getLimitTimeouts(Transport\iLimiter $limiter)