4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
+ declare (strict_types=1 );
7
8
namespace Magento \Framework \lock \Backend ;
8
9
10
+ use Magento \Framework \App \ResourceConnection ;
11
+
9
12
class Database implements \Magento \Framework \Lock \LockManagerInterface
10
13
{
11
- /** @var \Magento\Framework\App\ ResourceConnection */
14
+ /** @var ResourceConnection */
12
15
private $ resource ;
13
16
14
17
public function __construct (
15
- \ Magento \ Framework \ App \ ResourceConnection $ resource
18
+ ResourceConnection $ resource
16
19
)
17
20
{
18
21
$ this ->resource = $ resource ;
@@ -22,9 +25,10 @@ public function __construct(
22
25
* Sets a lock for name
23
26
*
24
27
* @param string $name lock name
28
+ * @param int $timeout How long to wait lock acquisition in seconds, negative value means infinite timeout
25
29
* @return bool
26
30
*/
27
- public function setLock ($ name , $ timeout = -1 )
31
+ public function setLock (string $ name , int $ timeout = -1 ): bool
28
32
{
29
33
return (bool )$ this ->resource ->getConnection ()->query ("SELECT GET_LOCK(?, ?); " , array ((string )$ name , (int )$ timeout ))
30
34
->fetchColumn ();
@@ -36,7 +40,7 @@ public function setLock($name, $timeout = -1)
36
40
* @param string $name lock name
37
41
* @return bool
38
42
*/
39
- public function releaseLock ($ name )
43
+ public function releaseLock (string $ name ): bool
40
44
{
41
45
return (bool )$ this ->resource ->getConnection ()->query ("SELECT RELEASE_LOCK(?); " , array ((string )$ name ))->fetchColumn ();
42
46
}
@@ -47,7 +51,7 @@ public function releaseLock($name)
47
51
* @param string $name lock name
48
52
* @return bool
49
53
*/
50
- public function isLocked ($ name )
54
+ public function isLocked (string $ name ): bool
51
55
{
52
56
return (bool )$ this ->resource ->getConnection ()->query ("SELECT IS_USED_LOCK(?); " , array ((string )$ name ))->fetchColumn ();
53
57
}
0 commit comments