Skip to content

Commit

Permalink
Bug fixes with the Service Provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
deltoss committed Jan 20, 2019
1 parent dcab651 commit 4a8de4c
Showing 1 changed file with 13 additions and 34 deletions.
47 changes: 13 additions & 34 deletions src/Providers/SentinelDatabasePermissionsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@
use Deltoss\SentinelDatabasePermissions\AbilityCategories\IlluminateAbilityCategoryRepository;
use Symfony\Component\HttpFoundation\Response;

class SentinelDatabasePermissionsServiceProvider extends ServiceProvider
class SentinelDatabasePermissionsServiceProvider extends SentinelServiceProvider
{
/**
* {@inheritDoc}
*/
public function boot()
{
}

/**
* Register the service provider.
*
Expand All @@ -28,7 +35,10 @@ public function register()
$this->registerAbilityCategories();
$this->extendSentinel();
$this->setConfigOverrides();
$this->setSentinelOverrides();
// We do the Sentinel overrides again,
// as the configs was changed and
// adjusted.
parent::setOverrides();
$this->setPermissionOverrides();
}

Expand Down Expand Up @@ -178,37 +188,6 @@ protected function setConfigOverrides()
]);
}

/**
* Set the overrides for Sentinel models.
*
* @return void
*/
protected function setSentinelOverrides()
{
// We do the Sentinel overrides again,
// as Sentinel Database Permissions
// automatically changes the used
// models conditionally.
$sentinelConfig = $this->app['config']->get('cartalyst.sentinel');
$users = $sentinelConfig['users']['model'];
$roles = $sentinelConfig['roles']['model'];
$permissions = $sentinelConfig['permissions']['class'];

if (class_exists($users)) {
if (method_exists($users, 'setRolesModel')) {
forward_static_call_array([ $users, 'setRolesModel' ], [ $roles ]);
}

if (method_exists($users, 'setPermissionsClass')) {
forward_static_call_array([ $users, 'setPermissionsClass' ], [ $permissions ]);
}
}

if (class_exists($roles) && method_exists($roles, 'setUsersModel')) {
forward_static_call_array([ $roles, 'setUsersModel' ], [ $users ]);
}
}

/**
* Performs the necessary overrides to set the
* Sentinel and permission models from the configs.
Expand Down Expand Up @@ -275,7 +254,7 @@ protected function setPermissionOverrides()
*/
public function provides()
{
$originalProvides = (new SentinelServiceProvider($this->app))->provides();
$originalProvides = parent::provides();
return array_merge($originalProvides, [
'sentinel.abilities',
'sentinel.ability_categories'
Expand Down

0 comments on commit 4a8de4c

Please sign in to comment.