RedisSentinelManager::getVersionedManager()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Monospice\LaravelRedisSentinel;
4
5
use Monospice\LaravelRedisSentinel\Contracts\Factory;
6
use Monospice\LaravelRedisSentinel\Manager\VersionedRedisSentinelManager;
7
use Monospice\SpicyIdentifiers\DynamicMethod;
8
9
/**
10
 * Enables Laravel's Redis database driver to accept configuration options for
11
 * Redis Sentinel connections independently. Replaces Laravel's RedisManager
12
 * for Redis Sentinel connections.
13
 *
14
 * By default, Laravel's Redis service permits a single set of configuration
15
 * options for all of the Redis connections passed to the Predis client. This
16
 * prevents us from declaring separate parameters for individual Redis services
17
 * managed by Sentinel. For example, we may wish to connect to a separate Redis
18
 * Sentinel service cluster set, or use a separate Redis database, for caching
19
 * queues, and sessions. This wrapper class enables us to declare parameters
20
 * for each connection in the "redis-sentinel" block of the database
21
 * configuration which it will use to configure individual clients.
22
 *
23
 * Laravel changed the public interface of the RedisManager class in version
24
 * 5.4.20. Because this package extends the functionality of that class, the
25
 * implementation needed to change to match the modified interface. To avoid
26
 * frivolous package versioning and simplify installation and upgrade through
27
 * composer, this class handles any small differences between minor Laravel
28
 * versions by wrapping implementations of RedisSentinelManager for each
29
 * diverging Laravel version.
30
 *
31
 * @category Package
32
 * @package  Monospice\LaravelRedisSentinel
33
 * @author   Cy Rossignol <[email protected]>
34
 * @license  See LICENSE file
35
 * @link     http://github.com/monospice/laravel-redis-sentinel-drivers
36
 */
37
class RedisSentinelManager implements Factory
38
{
39
    /**
40
     * The RedisSentinelManager instance for the current version of Laravel
41
     *
42
     * @var VersionedRedisSentinelManager
43
     */
44
    private $versionedManager;
45
46
    /**
47
     * Wrap the provided RedisSentinelManager instance that manages Sentinel
48
     * connections for the current version of Laravel.
49
     *
50
     * @param VersionedRedisSentinelManager $versionedManager Manages Redis
51
     * Sentinel connections for the current version of Laravel
52
     */
53
    public function __construct(VersionedRedisSentinelManager $versionedManager)
54
    {
55
        $this->versionedManager = $versionedManager;
56
    }
57
58
    /**
59
     * Get the current RedisSentinelManager instance that manages Sentinel
60
     * connections for the current version of Laravel.
61
     *
62
     * @return VersionedRedisSentinelManager The versioned implementation of
63
     * RedisSentinelManager
64
     */
65
    public function getVersionedManager()
66
    {
67
        return $this->versionedManager;
68
    }
69
70
    /**
71
     * Get a Redis Sentinel connection by name.
72
     *
73
     * @param string|null $name The name of the connection as defined in the
74
     * application's configuration
75
     *
76
     * @return \Illuminate\Redis\Connections\Connection The requested Redis
77
     * Sentinel connection
78
     */
79
    public function connection($name = null)
80
    {
81
        return $this->versionedManager->connection($name);
82
    }
83
84
    /**
85
     * Pass method calls to the RedisSentinelManager instance for the current
86
     * version of Laravel.
87
     *
88
     * @param string $methodName The name of the called method
89
     * @param array  $arguments  The arguments passed to the called method
90
     *
91
     * @return mixed The return value from the underlying method
92
     */
93
    public function __call($methodName, array $arguments)
94
    {
95
        return DynamicMethod::from($methodName)
96
            ->callOn($this->versionedManager, $arguments);
97
    }
98
}
99