for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Shieldon package.
*
* (c) Terry L. <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Shieldon\Firewall\Firewall\Driver;
use Shieldon\Firewall\Driver\RedisDriver;
use Redis;
use RedisException;
/**
* Get Redis driver.
class ItemRedisDriver
{
* Initialize and get the instance.
* @param array $setting The configuration of that driver.
* @return RedisDriver|null
public static function get(array $setting)
$instance = null;
try {
$host = '127.0.0.1';
$port = 6379;
if (!empty($setting['host'])) {
$host = $setting['host'];
}
if (!empty($setting['port'])) {
$port = $setting['port'];
// Create a Redis instance.
$redis = new Redis();
$redis->connect($host, $port);
if (!empty($setting['auth'])) {
// @codeCoverageIgnoreStart
$redis->auth($setting['auth']);
// @codeCoverageIgnoreEnd
// Use Redis data driver.
$instance = new RedisDriver($redis);
} catch(RedisException $e) {
echo $e->getMessage();
return $instance;