1 | <?php |
||
56 | class Manager extends ObjectAbstract implements ManagerInterface |
||
57 | { |
||
58 | /** |
||
59 | * drivers |
||
60 | * |
||
61 | * @var DriverInterface[] |
||
62 | * @access protected |
||
63 | */ |
||
64 | protected $drivers = []; |
||
65 | |||
66 | /** |
||
67 | * driver weight factor |
||
68 | * |
||
69 | * @var array |
||
70 | * @access protected |
||
71 | */ |
||
72 | protected $factors = []; |
||
73 | |||
74 | /** |
||
75 | * Ping driver before returns it |
||
76 | * |
||
77 | * @var bool |
||
78 | * @access protected |
||
79 | */ |
||
80 | protected $ping_driver = false; |
||
81 | |||
82 | /** |
||
83 | * Constructor |
||
84 | * |
||
85 | * @param array $properties |
||
86 | * @access public |
||
87 | */ |
||
88 | public function __construct(array $properties = []) |
||
92 | |||
93 | /** |
||
94 | * Specify a weighting factor for the driver. normally 1 - 10 |
||
95 | * |
||
96 | * {@inheritDoc} |
||
97 | * @param int $factor weight factor for round-robin |
||
98 | */ |
||
99 | public function addDriver(DriverInterface $driver, /*# int */ $factor = 1) |
||
112 | |||
113 | /** |
||
114 | * Get a driver with a tag matched |
||
115 | * |
||
116 | * {@inheritDoc} |
||
117 | */ |
||
118 | public function getDriver(/*# string */ $tag = '')/*# : DriverInterface */ |
||
132 | |||
133 | /** |
||
134 | * Return a unique string id of the driver |
||
135 | * |
||
136 | * @param DriverInterface $driver |
||
137 | * @return string |
||
138 | * @access protected |
||
139 | */ |
||
140 | protected function getDriverId(DriverInterface $driver)/*# : string */ |
||
144 | |||
145 | /** |
||
146 | * Make sure factor in the range of 1 - 10 |
||
147 | * |
||
148 | * @param int $factor |
||
149 | * @return int |
||
150 | * @access protected |
||
151 | */ |
||
152 | protected function fixFactor(/*# int */ $factor)/*# : int */ |
||
157 | |||
158 | /** |
||
159 | * Match drivers with tag |
||
160 | * |
||
161 | * @param string $tag tag to match |
||
162 | * @return array |
||
163 | * @access protected |
||
164 | */ |
||
165 | protected function driverMatcher(/*# string */ $tag)/*# : array */ |
||
175 | |||
176 | /** |
||
177 | * Expand into $matched with factor weight |
||
178 | * |
||
179 | * @param array &$matched |
||
180 | * @param string $id |
||
181 | * @access protected |
||
182 | */ |
||
183 | protected function expandWithFactor(array &$matched, /*# string */ $id) |
||
191 | |||
192 | /** |
||
193 | * Match driver with $tag |
||
194 | * |
||
195 | * @param string $tag |
||
196 | * @param DriverInterface $driver |
||
197 | * @return bool |
||
198 | * @access protected |
||
199 | */ |
||
200 | protected function tagMatched( |
||
216 | |||
217 | /** |
||
218 | * Ping driver before match it |
||
219 | * |
||
220 | * @param DriverInterface $driver |
||
221 | * @access protected |
||
222 | */ |
||
223 | protected function pingDriver(DriverInterface $driver)/*# : bool */ |
||
227 | } |
||
228 |