File tree Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,9 @@ public function getConfigTreeBuilder()
13
13
14
14
$ treeBuilder ->getRootNode ()
15
15
->children ()
16
- ->arrayNode ('exclude_route ' )->end ()
16
+ ->arrayNode ('exclude_route ' )
17
+ ->scalarPrototype ()->end ()
18
+ ->end ()
17
19
->end ()
18
20
;
19
21
Original file line number Diff line number Diff line change 6
6
use DateTime ;
7
7
use Doctrine \ORM \EntityManagerInterface ;
8
8
use FluffyFactory \Bundle \UserStatsBundle \Entity \UserStatsLines ;
9
+ use Symfony \Component \DependencyInjection \ParameterBag \ContainerBagInterface ;
9
10
use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
10
11
use Symfony \Component \HttpKernel \Event \RequestEvent ;
11
12
use Symfony \Component \Security \Core \Security ;
@@ -14,11 +15,13 @@ class UserStatsSubscriber implements EventSubscriberInterface
14
15
{
15
16
private $ security ;
16
17
private $ em ;
18
+ private $ containerBag ;
17
19
18
- public function __construct (Security $ security , EntityManagerInterface $ em )
20
+ public function __construct (Security $ security , EntityManagerInterface $ em, ContainerBagInterface $ containerBag )
19
21
{
20
22
$ this ->security = $ security ;
21
23
$ this ->em = $ em ;
24
+ $ this ->containerBag = $ containerBag ;
22
25
}
23
26
24
27
/**
@@ -39,8 +42,16 @@ public function onKernelRequest(RequestEvent $event)
39
42
{
40
43
/** @var User $user */
41
44
$ user = $ this ->security ->getUser ();
45
+ $ route = $ event ->getRequest ()->get ('_route ' );
46
+
47
+ if ($ user && $ route ) {
48
+
49
+ $ excludeRoute = $ this ->containerBag ->get ('fluffy_user_stats ' )['exclude_route ' ];
50
+
51
+ if ($ excludeRoute && in_array ($ route , $ excludeRoute )) {
52
+ return ;
53
+ }
42
54
43
- if ($ user && $ event ->getRequest ()->get ('_route ' )) {
44
55
$ user ->setLastVisited (new DateTime ());
45
56
$ user ->setNbPageViews ($ user ->getNbPageViews () + 1 );
46
57
Original file line number Diff line number Diff line change @@ -17,6 +17,13 @@ composer require fluffy-factory/user-stats-bundle
17
17
18
18
## Configuration
19
19
20
+ You can create your own configuration in ` config/packages/fluffy_user_stats.yaml ` :
21
+
22
+ ``` yaml
23
+ user_stats :
24
+ exclude_route : ['homepage', 'contact']
25
+ ` ` `
26
+
20
27
### Entity
21
28
22
29
Add mixin Class ` use UserStats` in your User entity
You can’t perform that action at this time.
0 commit comments