@@ -6,56 +6,64 @@ RequestLimitBundle
66This bundle is a simple solution to restrict user access
77to some controller for a specified timeline.
88
9- This could be used for different cases when you need to pre
10-
9+ This functionality could be used for different cases when you need to:
1110- prevent flood - pushing users of irrelevant data;
12- - prevent user to visit page very often, etc.
11+ - prevent a user from accessing the certain endpoint very often, etc.
1312
1413Installation
1514=============
1615
17- 1 ) Require bundle with :
16+ 1 ) Install package via :
1817``` bash
19- composer require
18+ composer require nv/request-limit-bundle
19+ ```
20+
21+ 2 ) Register bundle :
22+
23+ In ` app/AppKernel.php ` prior to Symfony version ` 4.0 ` :
24+ ``` php
25+ public function registerBundles()
26+ {
27+ $bundles = [
28+ // ... ,
29+ new NV\RequestLimitBundle\NVRequestLimitBundle()
30+ ];
31+
32+ // ...
33+ return $bundles;
34+ }
2035```
2136
22- 2 ) Register bundle in AppKernel:
37+ In ` config/bundles.php ` when Symfony version is ` 4.0 ` and higher
2338``` php
24- public function registerBundles()
25- {
26- $bundles = [
27- ... ,
28- new NV\RequestLimitBundle\NVRequestLimitBundle()
29- ];
30- ...
31- }
39+ return [
40+ //... other bundles
41+ NV\RequestLimitBundle\NVRequestLimitBundle::class => ['all' => true]
42+ ];
3243```
3344
34- 3 ) Configure bundle according to provider you use:
35- - [ Memcached] ( https://github.com/NovikovViktor/RequestLimitBundle/blob/master/Resources/docs/memcached.md )
36- - [ MySQL] ( https://github.com/NovikovViktor/RequestLimitBundle/blob/master/Resources/docs/mysql.md )
45+ 3 ) Configure the bundle according to the provider you would like to use.
46+ Out of the box, we provide the Memcached and MySQL providers. To see configuration options, see the docs below.
47+
48+ - [ Memcached provider configuration] ( https://github.com/NovikovViktor/RequestLimitBundle/blob/master/Resources/docs/memcached.md )
49+ - [ MySQL provider configuration] ( https://github.com/NovikovViktor/RequestLimitBundle/blob/master/Resources/docs/mysql.md )
50+
51+ If you want to use other storage, you can implement your provider.
3752
38534 ) Specify ` restriction_time ` in seconds:
3954``` yml
4055nv_request_limit :
41- restriction_time : 5
56+ # ... options for provider configuration
57+ restriction_time : 5 # 5 seconds
4258` ` `
4359
4460Usage
4561=============
4662
47- In your controller action add following line to restrict user access by user id:
48- ` ` ` php
49- $this->get('nv.request_limit.request_restrictor')->restrictRequestByUserId($userId);
50- ```
51- or following to restrict by user IP:
63+ In your action, add the following line to restrict access by some specific application user artifact (e.g., user id, user IP, etc.):
5264` ` ` php
53- $this->get('nv.request_limit.request_restrictor')->restrictRequestByIp($userIp);
65+ $artifact = 'e.g. get user id or IP here';
66+ $this->get('nv.request_limit.restrictor')->blockBy($artifact);
5467```
5568
56- These will restrict user access to the action for 10 minutes.
57-
58- TODO
59- =========
60-
61- 1 ) Write tests
69+ These will restrict user access for a time frame specified in your configuration (5 seconds accordingly to).
0 commit comments