6 declare(strict_types=1);
30 private $deploymentConfig;
40 private $currentLock =
false;
54 $this->prefix = $prefix;
66 public function lock(
string $name,
int $timeout = -1): bool
75 if ($this->currentLock) {
78 'Current connection is already holding lock for $1, only single lock allowed',
84 $result = (bool)$this->resource->getConnection()->query(
85 "SELECT GET_LOCK(?, ?);",
86 [(
string)
$name, (
int)$timeout]
90 $this->currentLock =
$name;
107 $result = (bool)$this->resource->getConnection()->query(
108 "SELECT RELEASE_LOCK(?);",
113 $this->currentLock =
false;
130 return (
bool)$this->resource->getConnection()->query(
131 "SELECT IS_USED_LOCK(?);",
145 private function addPrefix(
string $name): string
149 if (strlen(
$name) > 64) {
161 private function getPrefix(): string
163 if ($this->prefix ===
null) {
164 $this->prefix = (string)$this->deploymentConfig->get(
172 return $this->prefix;
__construct(ResourceConnection $resource, DeploymentConfig $deploymentConfig, string $prefix=null)
const CONFIG_PATH_DB_CONNECTION_DEFAULT
lock(string $name, int $timeout=-1)
if(!isset($_GET['name'])) $name