@@ -51,7 +51,7 @@ public function register()
5151 $ this ->setupConfig ();
5252 $ this ->registerExceptionNotifyManager ();
5353 $ this ->registerCollectorManager ();
54- $ this ->registerRateLimiterFactory ();
54+ $ this ->registerRateLimiter ();
5555 }
5656
5757 /**
@@ -99,20 +99,34 @@ protected function registerExceptionNotifyManager()
9999 $ this ->app ->alias (ExceptionNotifyManager::class, 'exception.notifier ' );
100100 }
101101
102- protected function registerRateLimiterFactory ()
102+ protected function registerRateLimiter ()
103103 {
104- $ this ->app ->singleton (RateLimiterFactory::class, function (Container $ app ) {
105- return new RateLimiterFactory ([
106- 'id ' => 'exception_notify ' ,
107- 'policy ' => 'token_bucket ' ,
108- 'limit ' => $ app ['config ' ]['exception-notify.rate_limiter.limit ' ],
109- 'rate ' => [
110- 'interval ' => $ app ['config ' ]['exception-notify.rate_limiter.interval ' ],
111- ],
112- ], new CacheStorage ($ app ->make ($ app ['config ' ]['exception-notify.rate_limiter.cache_adapter ' ])));
104+ $ this ->app ->singleton (CacheStorage::class, function (Container $ app ) {
105+ return new CacheStorage (
106+ $ app ->make (
107+ $ app ['config ' ]['exception-notify.rate_limiter.storage.class ' ],
108+ $ app ['config ' ]['exception-notify.rate_limiter.storage.parameters ' ]
109+ )
110+ );
113111 });
112+ $ this ->app ->alias (CacheStorage::class, 'exception.rate-limiter.storage ' );
114113
115- $ this ->app ->alias (RateLimiterFactory::class, 'exception.rate-limiter-factory ' );
114+ $ this ->app ->singleton (RateLimiterFactory::class, function (Container $ app ) {
115+ return new RateLimiterFactory (
116+ array_merge ([
117+ 'id ' => 'exception-notify ' ,
118+ 'policy ' => 'token_bucket ' ,
119+ 'limit ' => 6 ,
120+ 'interval ' => '1 minutes ' ,
121+ 'rate ' => [
122+ 'amount ' => 1 ,
123+ 'interval ' => '1 minutes ' ,
124+ ],
125+ ], $ app ['config ' ]['exception-notify.rate_limiter.config ' ]),
126+ $ this ->app ->make (CacheStorage::class)
127+ );
128+ });
129+ $ this ->app ->alias (RateLimiterFactory::class, 'exception.rate-limiter.factory ' );
116130 }
117131
118132 protected function registerReportingEvent ()
0 commit comments