mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-27 22:33:10 +09:00
Validate queue driver configuration before saving
This commit is contained in:
parent
0ee9747a22
commit
36af489b15
7 changed files with 80 additions and 6 deletions
|
|
@ -61,6 +61,17 @@ class DB implements QueueInterface
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate driver configuration.
|
||||
*
|
||||
* @param mixed $config
|
||||
* @return bool
|
||||
*/
|
||||
public static function validateConfig($config): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -65,6 +65,17 @@ class Dummy implements QueueInterface
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate driver configuration.
|
||||
*
|
||||
* @param mixed $config
|
||||
* @return bool
|
||||
*/
|
||||
public static function validateConfig($config): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -66,6 +66,37 @@ class Redis implements QueueInterface
|
|||
return class_exists('\\Redis');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate driver configuration.
|
||||
*
|
||||
* @param mixed $config
|
||||
* @return bool
|
||||
*/
|
||||
public static function validateConfig($config): bool
|
||||
{
|
||||
try
|
||||
{
|
||||
$test = new \Redis;
|
||||
$test->connect($config['host'], $config['port'] ?? 6379);
|
||||
if (isset($config['user']) || isset($config['pass']))
|
||||
{
|
||||
$auth = [];
|
||||
if (isset($config['user']) && $config['user']) $auth[] = $config['user'];
|
||||
if (isset($config['pass']) && $config['pass']) $auth[] = $config['pass'];
|
||||
$test->auth(count($auth) > 1 ? $auth : $auth[0]);
|
||||
}
|
||||
if (isset($config['dbnum']))
|
||||
{
|
||||
$test->select(intval($config['dbnum']));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (\Throwable $th)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
|
@ -77,18 +108,17 @@ class Redis implements QueueInterface
|
|||
{
|
||||
$this->_conn = new \Redis;
|
||||
$this->_conn->connect($config['host'], $config['port'] ?? 6379);
|
||||
if(isset($config['user']) || isset($config['pass']))
|
||||
if (isset($config['user']) || isset($config['pass']))
|
||||
{
|
||||
$auth = [];
|
||||
if (isset($config['user']) && $config['user']) $auth[] = $config['user'];
|
||||
if (isset($config['pass']) && $config['pass']) $auth[] = $config['pass'];
|
||||
$this->_conn->auth(count($auth) > 1 ? $auth : $auth[0]);
|
||||
}
|
||||
if(isset($config['dbnum']))
|
||||
if (isset($config['dbnum']))
|
||||
{
|
||||
$this->_conn->select(intval($config['dbnum']));
|
||||
}
|
||||
|
||||
$this->_key = 'rxQueue_' . substr(hash_hmac('sha1', 'rxQueue_', config('crypto.authentication_key')), 0, 24);
|
||||
}
|
||||
catch (\RedisException $e)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue