diff --git a/src/Commands/GroupAdd.php b/src/Commands/GroupAdd.php new file mode 100644 index 0000000..20df943 --- /dev/null +++ b/src/Commands/GroupAdd.php @@ -0,0 +1,46 @@ +argument('policy')); + array_walk($params, function (&$value) { + $value = trim($value); + }); + $ret = Enforcer::addGroupingPolicy(...$params); + if ($ret) { + $this->info('Grouping `' . implode(', ', $params) . '` created'); + } else { + $this->error('Grouping `' . implode(', ', $params) . '` creation failed'); + } + + return $ret ? 0 : 1; + } +} diff --git a/src/LauthzServiceProvider.php b/src/LauthzServiceProvider.php index 8620b57..d433cb2 100644 --- a/src/LauthzServiceProvider.php +++ b/src/LauthzServiceProvider.php @@ -2,50 +2,47 @@ namespace Lauthz; +use Illuminate\Support\ServiceProvider; use Lauthz\Models\Rule; use Lauthz\Observers\RuleObserver; -use Illuminate\Support\ServiceProvider; -class LauthzServiceProvider extends ServiceProvider -{ - /** - * Perform post-registration booting of services. - */ - public function boot() - { - if ($this->app->runningInConsole()) { - $this->publishes([__DIR__.'/../database/migrations' => database_path('migrations')], 'laravel-lauthz-migrations'); - $this->publishes([__DIR__.'/../config/lauthz-rbac-model.conf' => config_path('lauthz-rbac-model.conf')], 'laravel-lauthz-config'); - $this->publishes([__DIR__.'/../config/lauthz.php' => config_path('lauthz.php')], 'laravel-lauthz-config'); +class LauthzServiceProvider extends ServiceProvider { + /** + * Perform post-registration booting of services. + */ + public function boot() { + if ($this->app->runningInConsole()) { + $this->publishes([__DIR__ . '/../database/migrations' => database_path('migrations')], 'laravel-lauthz-migrations'); + $this->publishes([__DIR__ . '/../config/lauthz-rbac-model.conf' => config_path('lauthz-rbac-model.conf')], 'laravel-lauthz-config'); + $this->publishes([__DIR__ . '/../config/lauthz.php' => config_path('lauthz.php')], 'laravel-lauthz-config'); - $this->commands([ - Commands\PolicyAdd::class, - Commands\RoleAssign::class, - ]); - } + $this->commands([ + Commands\GroupAdd::class, + Commands\PolicyAdd::class, + Commands\RoleAssign::class, + ]); + } - $this->mergeConfigFrom(__DIR__.'/../config/lauthz.php', 'lauthz'); + $this->mergeConfigFrom(__DIR__ . '/../config/lauthz.php', 'lauthz'); - $this->bootObserver(); - } + $this->bootObserver(); + } - /** - * Boot Observer. - * - * @return void - */ - protected function bootObserver() - { - Rule::observe(new RuleObserver()); - } + /** + * Boot Observer. + * + * @return void + */ + protected function bootObserver() { + Rule::observe(new RuleObserver()); + } - /** - * Register bindings in the container. - */ - public function register() - { - $this->app->singleton('enforcer', function ($app) { - return new EnforcerManager($app); - }); - } + /** + * Register bindings in the container. + */ + public function register() { + $this->app->singleton('enforcer', function ($app) { + return new EnforcerManager($app); + }); + } }