From 4c8583cdf736200351ac4ff6c42c75fb3b1cf4d6 Mon Sep 17 00:00:00 2001 From: Paras Malhotra Date: Thu, 15 Oct 2020 13:32:49 +0530 Subject: [PATCH 1/3] [9.x] Add a separate Rate Limiting Service Provider (Deferrable) --- src/Illuminate/Cache/CacheServiceProvider.php | 4 +-- .../Cache/RateLimitingServiceProvider.php | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100755 src/Illuminate/Cache/RateLimitingServiceProvider.php diff --git a/src/Illuminate/Cache/CacheServiceProvider.php b/src/Illuminate/Cache/CacheServiceProvider.php index e0616768e373..46fa0ae2615c 100755 --- a/src/Illuminate/Cache/CacheServiceProvider.php +++ b/src/Illuminate/Cache/CacheServiceProvider.php @@ -30,8 +30,6 @@ public function register() $this->app->singleton('memcached.connector', function () { return new MemcachedConnector; }); - - $this->app->singleton(RateLimiter::class); } /** @@ -42,7 +40,7 @@ public function register() public function provides() { return [ - 'cache', 'cache.store', 'cache.psr6', 'memcached.connector', RateLimiter::class, + 'cache', 'cache.store', 'cache.psr6', 'memcached.connector', ]; } } diff --git a/src/Illuminate/Cache/RateLimitingServiceProvider.php b/src/Illuminate/Cache/RateLimitingServiceProvider.php new file mode 100755 index 000000000000..ebc77600aef3 --- /dev/null +++ b/src/Illuminate/Cache/RateLimitingServiceProvider.php @@ -0,0 +1,31 @@ +app->singleton(RateLimiter::class); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return [ + RateLimiter::class, + ]; + } +} From 14eaa92fab0f0ddd06b0f9bf0099de9305a5e454 Mon Sep 17 00:00:00 2001 From: Paras Malhotra Date: Thu, 15 Oct 2020 13:54:12 +0530 Subject: [PATCH 2/3] Add provider to tests --- tests/Integration/Http/ThrottleRequestsTest.php | 6 ++++++ tests/Integration/Http/ThrottleRequestsWithRedisTest.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/tests/Integration/Http/ThrottleRequestsTest.php b/tests/Integration/Http/ThrottleRequestsTest.php index c836f916ffa5..de12863f2cbf 100644 --- a/tests/Integration/Http/ThrottleRequestsTest.php +++ b/tests/Integration/Http/ThrottleRequestsTest.php @@ -3,6 +3,7 @@ namespace Illuminate\Tests\Integration\Http; use Illuminate\Cache\RateLimiter; +use Illuminate\Cache\RateLimitingServiceProvider; use Illuminate\Cache\RateLimiting\GlobalLimit; use Illuminate\Container\Container; use Illuminate\Http\Exceptions\ThrottleRequestsException; @@ -98,4 +99,9 @@ public function testLimitingUsingNamedLimiter() $this->assertEquals(Carbon::now()->addSeconds(2)->getTimestamp(), $e->getHeaders()['X-RateLimit-Reset']); } } + + protected function getPackageProviders($app) + { + return [RateLimitingServiceProvider::class]; + } } diff --git a/tests/Integration/Http/ThrottleRequestsWithRedisTest.php b/tests/Integration/Http/ThrottleRequestsWithRedisTest.php index 34b34d4f65ae..8f27c88b7ea7 100644 --- a/tests/Integration/Http/ThrottleRequestsWithRedisTest.php +++ b/tests/Integration/Http/ThrottleRequestsWithRedisTest.php @@ -2,6 +2,7 @@ namespace Illuminate\Tests\Integration\Http; +use Illuminate\Cache\RateLimitingServiceProvider; use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis; use Illuminate\Routing\Middleware\ThrottleRequestsWithRedis; use Illuminate\Support\Carbon; @@ -61,4 +62,9 @@ public function testLockOpensImmediatelyAfterDecay() } }); } + + protected function getPackageProviders($app) + { + return [RateLimitingServiceProvider::class]; + } } From 27fbe7c7af327a9c939f97ac92c8048feaeea6bf Mon Sep 17 00:00:00 2001 From: Paras Malhotra Date: Thu, 15 Oct 2020 13:57:28 +0530 Subject: [PATCH 3/3] fix styleci --- tests/Integration/Http/ThrottleRequestsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Http/ThrottleRequestsTest.php b/tests/Integration/Http/ThrottleRequestsTest.php index de12863f2cbf..57d03b397e51 100644 --- a/tests/Integration/Http/ThrottleRequestsTest.php +++ b/tests/Integration/Http/ThrottleRequestsTest.php @@ -3,8 +3,8 @@ namespace Illuminate\Tests\Integration\Http; use Illuminate\Cache\RateLimiter; -use Illuminate\Cache\RateLimitingServiceProvider; use Illuminate\Cache\RateLimiting\GlobalLimit; +use Illuminate\Cache\RateLimitingServiceProvider; use Illuminate\Container\Container; use Illuminate\Http\Exceptions\ThrottleRequestsException; use Illuminate\Routing\Middleware\ThrottleRequests;