12
12
use Jaspaul \LaravelRollout \Console \CreateCommand ;
13
13
use Jaspaul \LaravelRollout \Console \DeleteCommand ;
14
14
use Jaspaul \LaravelRollout \Console \AddUserCommand ;
15
+ use Jaspaul \LaravelRollout \Console \AddGroupCommand ;
15
16
use Jaspaul \LaravelRollout \Console \EveryoneCommand ;
16
17
use Illuminate \Contracts \Config \Repository as Config ;
17
18
use Jaspaul \LaravelRollout \Console \DeactivateCommand ;
18
19
use Jaspaul \LaravelRollout \Console \PercentageCommand ;
19
20
use Jaspaul \LaravelRollout \Console \RemoveUserCommand ;
21
+ use Jaspaul \LaravelRollout \Console \RemoveGroupCommand ;
20
22
use Illuminate \Support \ServiceProvider as IlluminateServiceProvider ;
21
23
22
24
class ServiceProvider extends IlluminateServiceProvider
@@ -44,17 +46,21 @@ public function boot()
44
46
$ driver = new Cache ($ app ->make ('cache.store ' ));
45
47
}
46
48
47
- return new Rollout ($ driver );
49
+ $ this ->loadGroups ($ rollout = new Rollout ($ driver ), $ config ->get ('laravel-rollout.groups ' ));
50
+
51
+ return $ rollout ;
48
52
});
49
53
50
54
$ this ->commands ([
55
+ AddGroupCommand::class,
51
56
AddUserCommand::class,
52
57
CreateCommand::class,
53
58
DeactivateCommand::class,
54
59
DeleteCommand::class,
55
60
EveryoneCommand::class,
56
61
ListCommand::class,
57
62
PercentageCommand::class,
63
+ RemoveGroupCommand::class,
58
64
RemoveUserCommand::class
59
65
]);
60
66
}
@@ -67,7 +73,8 @@ public function boot()
67
73
public function register ()
68
74
{
69
75
$ this ->mergeConfigFrom (
70
- __DIR__ .'/../resources/config/laravel-rollout.php ' , 'laravel-rollout '
76
+ __DIR__ .'/../resources/config/laravel-rollout.php ' ,
77
+ 'laravel-rollout '
71
78
);
72
79
}
73
80
@@ -92,4 +99,19 @@ protected function loadMigrations()
92
99
{
93
100
$ this ->loadMigrationsFrom (__DIR__ .'/../resources/migrations ' );
94
101
}
102
+
103
+ /**
104
+ * Loads our groups
105
+ *
106
+ * @return void
107
+ */
108
+ protected function loadGroups (Rollout $ rollout , array $ groups )
109
+ {
110
+ foreach ($ groups as $ group ) {
111
+ $ instance = resolve ($ group );
112
+ $ rollout ->defineGroup ($ instance ->getName (), function ($ user = null ) use ($ instance ) {
113
+ return $ instance ->hasMember ($ user );
114
+ });
115
+ }
116
+ }
95
117
}
0 commit comments