@@ -28,18 +28,18 @@ class Locker
2828 /**
2929 * The connection instance.
3030 *
31- * @var \AltThree\Locker\Connections\ConnectionInterface
31+ * @var \AltThree\Locker\Connections\ConnectionInterface|callable
3232 */
3333 protected $ connection ;
3434
3535 /**
3636 * Create a new locker instance.
3737 *
38- * @param \AltThree\Locker\Connections\ConnectionInterface $connection
38+ * @param \AltThree\Locker\Connections\ConnectionInterface|callable $connection
3939 *
4040 * @return void
4141 */
42- public function __construct (ConnectionInterface $ connection )
42+ public function __construct ($ connection )
4343 {
4444 $ this ->connection = $ connection ;
4545 }
@@ -59,7 +59,7 @@ public function __construct(ConnectionInterface $connection)
5959 */
6060 public function make (string $ name , int $ timeout , int $ play = 500 , int $ interval = 100 , int $ attempts = 128 )
6161 {
62- return new Lock ($ this ->connection , $ name , $ timeout , $ play , $ interval , $ attempts );
62+ return new Lock ($ this ->resolveConnection () , $ name , $ timeout , $ play , $ interval , $ attempts );
6363 }
6464
6565 /**
@@ -95,4 +95,20 @@ public function execute(Closure $function, string $name, int $timeout, int $play
9595
9696 return $ result ;
9797 }
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+ }
98114}
0 commit comments