Skip to content

Commit

Permalink
feature: code style
Browse files Browse the repository at this point in the history
  • Loading branch information
krissss committed Sep 18, 2022
1 parent ddb854f commit 59af416
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Locker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public static function __callStatic($name, $arguments)
return static::createLock($name . $key, ...$arguments);
}

/**
* @var null|array
*/
protected static $defaultConfig = null;

/**
* 创建锁
* @param string $key
Expand All @@ -25,13 +30,19 @@ public static function __callStatic($name, $arguments)
*/
protected static function createLock(string $key, ?float $ttl = null, ?bool $autoRelease = null, ?string $prefix = null)
{
$config = config('plugin.webman-tech.symfony-lock.lock.default_config', []);
if (static::$defaultConfig === null) {
static::$defaultConfig = config('plugin.webman-tech.symfony-lock.lock.default_config', []);
}
$config = static::$defaultConfig;
$ttl = $ttl !== null ? $ttl : ($config['ttl'] ?? 300);
$autoRelease = $autoRelease !== null ? $autoRelease : ($config['auto_release'] ?? true);
$prefix = $prefix !== null ? $prefix : ($config['prefix'] ?? 'lock_');
return static::getLockFactory()->createLock($prefix . $key, $ttl, $autoRelease);
}

/**
* @var null|LockFactory
*/
protected static $factory = null;

/**
Expand Down

0 comments on commit 59af416

Please sign in to comment.