1010
1111namespace Atlas \Pdo ;
1212
13- use function stat ;
14- use function strtolower ;
15-
1613/**
1714 * @phpstan-type connectionStore array{
1815 * DEFAULT: ?Connection,
@@ -38,12 +35,6 @@ class ConnectionLocator
3835 */
3936 public const WRITE = 'WRITE ' ;
4037
41- /**
42- * @param mixed $arg
43- * @param mixed ...$args
44- *
45- * @return static
46- */
4738 static public function new (mixed $ arg , mixed ...$ args ) : static
4839 {
4940 if ($ arg instanceof Connection) {
@@ -66,24 +57,12 @@ static public function new(mixed $arg, mixed ...$args) : static
6657 self ::WRITE => [],
6758 ];
6859
69- /**
70- * @var Connection|null
71- */
7260 protected ?Connection $ read = null ;
7361
74- /**
75- * @var Connection|null
76- */
7762 protected ?Connection $ write = null ;
7863
79- /**
80- * @var bool
81- */
8264 protected bool $ lockToWrite = false ;
8365
84- /**
85- * @var bool
86- */
8766 protected bool $ logQueries = false ;
8867
8968 /**
@@ -108,22 +87,11 @@ public function __construct(
10887 ) {
10988 }
11089
111- /**
112- * @param callable $factory
113- *
114- * @return void
115- */
11690 public function setDefaultFactory (callable $ factory ) : void
11791 {
11892 $ this ->defaultFactory = $ factory ;
11993 }
12094
121- /**
122- * @param string $name
123- * @param callable $factory
124- *
125- * @return void
126- */
12795 public function setReadFactory (
12896 string $ name ,
12997 callable $ factory
@@ -132,12 +100,6 @@ public function setReadFactory(
132100 $ this ->readFactories [$ name ] = $ factory ;
133101 }
134102
135- /**
136- * @param string $name
137- * @param callable $factory
138- *
139- * @return void
140- */
141103 public function setWriteFactory (
142104 string $ name ,
143105 callable $ factory
@@ -146,9 +108,6 @@ public function setWriteFactory(
146108 $ this ->writeFactories [$ name ] = $ factory ;
147109 }
148110
149- /**
150- * @return Connection
151- */
152111 public function getDefault () : Connection
153112 {
154113 /** @var 'DEFAULT' $type */
@@ -164,9 +123,6 @@ public function getDefault() : Connection
164123 return $ this ->instances [$ type ];
165124 }
166125
167- /**
168- * @return Connection
169- */
170126 public function getRead () : Connection
171127 {
172128 if ($ this ->lockToWrite ) {
@@ -183,9 +139,6 @@ public function getRead() : Connection
183139 return $ this ->read ;
184140 }
185141
186- /**
187- * @return Connection
188- */
189142 public function getWrite () : Connection
190143 {
191144 if (! isset ($ this ->write )) {
@@ -198,13 +151,6 @@ public function getWrite() : Connection
198151 return $ this ->write ;
199152 }
200153
201- /**
202- * @param string $type
203- * @param array $factories
204- *
205- * @return Connection
206- * @throws Exception
207- */
208154 protected function getConnection (
209155 string $ type ,
210156 array $ factories
@@ -226,13 +172,6 @@ protected function getConnection(
226172 return $ this ->get ($ type , (string ) array_rand ($ factories ));
227173 }
228174
229- /**
230- * @param string $type
231- * @param string $name
232- *
233- * @return Connection
234- * @throws Exception
235- */
236175 public function get (
237176 string $ type ,
238177 string $ name
@@ -257,12 +196,6 @@ public function get(
257196 return $ this ->instances [$ type ][$ name ];
258197 }
259198
260- /**
261- * @param callable $factory
262- * @param string $label
263- *
264- * @return Connection
265- */
266199 protected function newConnection (
267200 callable $ factory ,
268201 string $ label
@@ -283,45 +216,26 @@ protected function newConnection(
283216 return $ connection ;
284217 }
285218
286- /**
287- * @return bool
288- */
289219 public function hasRead () : bool
290220 {
291221 return isset ($ this ->read );
292222 }
293223
294- /**
295- * @return bool
296- */
297224 public function hasWrite () : bool
298225 {
299226 return isset ($ this ->write );
300227 }
301228
302- /**
303- * @param bool $lockToWrite
304- *
305- * @return void
306- */
307229 public function lockToWrite (bool $ lockToWrite = true ) : void
308230 {
309231 $ this ->lockToWrite = $ lockToWrite ;
310232 }
311233
312- /**
313- * @return bool
314- */
315234 public function isLockedToWrite () : bool
316235 {
317236 return $ this ->lockToWrite ;
318237 }
319238
320- /**
321- * @param bool $logQueries
322- *
323- * @return void
324- */
325239 public function logQueries (bool $ logQueries = true ) : void
326240 {
327241 /** @var Connection|null $defaultConnection */
@@ -351,11 +265,6 @@ public function getQueries() : array
351265 return $ this ->queries ;
352266 }
353267
354- /**
355- * @param callable $queryLogger
356- *
357- * @return void
358- */
359268 public function setQueryLogger (callable $ queryLogger ) : void
360269 {
361270 $ this ->queryLogger = $ queryLogger ;
0 commit comments