44
55use Illuminate \Cache \CacheManager ;
66use Illuminate \Cache \RedisStore ;
7- use Illuminate \Foundation \Application ;
87use Illuminate \Queue \QueueManager ;
98use Illuminate \Queue \Connectors \RedisConnector ;
109use Illuminate \Session \CacheBasedSessionHandler ;
@@ -35,18 +34,18 @@ class RedisSentinelServiceProvider extends ServiceProvider
3534 public function boot ()
3635 {
3736 $ this ->addRedisSentinelCacheDriver ($ this ->app ->make ('cache ' ));
38- $ this ->addRedisSentinelSessionHandler ($ this ->app ->make ('session ' ));
3937 $ this ->addRedisSentinelQueueConnector ($ this ->app ->make ('queue ' ));
4038
39+ // Lumen removed session support since version 5.2, so we'll only bind
40+ // the Sentinel session handler if we're running Laravel.
41+ if (! $ this ->isLumenApplication ()) {
42+ $ this ->addRedisSentinelSessionHandler ($ this ->app ->make ('session ' ));
43+ }
44+
4145 // If we want Laravel's Redis API to use Sentinel, we'll remove the
4246 // "redis" service from the list of deferred services in the container:
4347 if ($ this ->shouldOverrideLaravelApi ()) {
44- $ deferredServices = $ this ->app ->getDeferredServices ();
45-
46- unset($ deferredServices ['redis ' ]);
47- unset($ deferredServices ['redis.connection ' ]);
48-
49- $ this ->app ->setDeferredServices ($ deferredServices );
48+ $ this ->removeDeferredRedisServices ();
5049 }
5150 }
5251
@@ -77,7 +76,7 @@ public function register()
7776
7877 /**
7978 * Replace the standard Laravel Redis service with the Redis Sentinel
80- * database driver so all redis operations use Sentinel connections.
79+ * database driver so all Redis operations use Sentinel connections.
8180 *
8281 * @return void
8382 */
@@ -92,6 +91,26 @@ protected function registerOverrides()
9291 });
9392 }
9493
94+ /**
95+ * Remove the standard Laravel Redis service from the bound deferred
96+ * services so they don't overwrite Redis Sentinel registrations.
97+ *
98+ * @return void
99+ */
100+ protected function removeDeferredRedisServices ()
101+ {
102+ if ($ this ->isLumenApplication ()) {
103+ return ;
104+ }
105+
106+ $ deferredServices = $ this ->app ->getDeferredServices ();
107+
108+ unset($ deferredServices ['redis ' ]);
109+ unset($ deferredServices ['redis.connection ' ]);
110+
111+ $ this ->app ->setDeferredServices ($ deferredServices );
112+ }
113+
95114 /**
96115 * Add "redis-sentinel" as an available driver option to the Laravel cache
97116 * manager.
@@ -168,17 +187,36 @@ protected function shouldOverrideLaravelApi()
168187
169188 /**
170189 * Get the fully-qualified class name of the RedisSentinelManager class
171- * for the current version of Laravel.
190+ * for the current version of Laravel or Lumen .
172191 *
173192 * @return string The class name of the appropriate RedisSentinelManager
174193 * with its namespace
175194 */
176195 protected function getVersionedRedisSentinelManagerClass ()
177196 {
178- if (version_compare (Application::VERSION , '5.4.20 ' , 'lt ' )) {
197+ if ($ this ->isLumenApplication ()) {
198+ $ appVersion = substr ($ this ->app ->version (), 7 , 3 );
199+ $ frameworkVersion = '5.4 ' ;
200+ } else {
201+ $ appVersion = \Illuminate \Foundation \Application::VERSION ;
202+ $ frameworkVersion = '5.4.20 ' ;
203+ }
204+
205+ if (version_compare ($ appVersion , $ frameworkVersion , 'lt ' )) {
179206 return Manager \Laravel540RedisSentinelManager::class;
180207 }
181208
182209 return Manager \Laravel5420RedisSentinelManager::class;
183210 }
211+
212+ /**
213+ * Determine if the current application runs the Lumen framework instead of
214+ * Laravel.
215+ *
216+ * @return bool True if running Lumen
217+ */
218+ protected function isLumenApplication ()
219+ {
220+ return $ this ->app instanceof \Laravel \Lumen \Application;
221+ }
184222}
0 commit comments