@@ -28,18 +28,18 @@ class Locker
28
28
/**
29
29
* The connection instance.
30
30
*
31
- * @var \AltThree\Locker\Connections\ConnectionInterface
31
+ * @var \AltThree\Locker\Connections\ConnectionInterface|callable
32
32
*/
33
33
protected $ connection ;
34
34
35
35
/**
36
36
* Create a new locker instance.
37
37
*
38
- * @param \AltThree\Locker\Connections\ConnectionInterface $connection
38
+ * @param \AltThree\Locker\Connections\ConnectionInterface|callable $connection
39
39
*
40
40
* @return void
41
41
*/
42
- public function __construct (ConnectionInterface $ connection )
42
+ public function __construct ($ connection )
43
43
{
44
44
$ this ->connection = $ connection ;
45
45
}
@@ -59,7 +59,7 @@ public function __construct(ConnectionInterface $connection)
59
59
*/
60
60
public function make (string $ name , int $ timeout , int $ play = 500 , int $ interval = 100 , int $ attempts = 128 )
61
61
{
62
- return new Lock ($ this ->connection , $ name , $ timeout , $ play , $ interval , $ attempts );
62
+ return new Lock ($ this ->resolveConnection () , $ name , $ timeout , $ play , $ interval , $ attempts );
63
63
}
64
64
65
65
/**
@@ -95,4 +95,20 @@ public function execute(Closure $function, string $name, int $timeout, int $play
95
95
96
96
return $ result ;
97
97
}
98
+
99
+ /**
100
+ * Resolve the connection instance.
101
+ *
102
+ * @return \AltThree\Locker\Connections\ConnectionInterface
103
+ */
104
+ protected function resolveConnection ()
105
+ {
106
+ if ($ this ->connection instanceof ConnectionInterface) {
107
+ return $ this ->connection ;
108
+ }
109
+
110
+ $ c = $ this ->connection ;
111
+
112
+ return $ this ->connection = $ c ();
113
+ }
98
114
}
0 commit comments