Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Role and Permission should be created based on config file #92

Open
nunomazer opened this issue May 28, 2016 · 0 comments
Open

Role and Permission should be created based on config file #92

nunomazer opened this issue May 28, 2016 · 0 comments

Comments

@nunomazer
Copy link
Contributor

nunomazer commented May 28, 2016

The registerRepositoryInterfaces() function in DefenderServiceProvider class is creating the Role and Permission singletons based on default package classes. This does not allows the repository pattern to provide expected behavior.

I'm using MongoDB and need to extend my models from a different class than default Eloquent\Model. Below are the key parts of this logic:

protected function registerRepositoryInterfaces()
{
    $this->app->singleton('defender.role', function ($app) {
        return new EloquentRoleRepository($app, new Role());
    });

    ...

    $this->app->singleton('defender.permission', function ($app) {
        return new EloquentPermissionRepository($app, new Permission());
    });

    ...

    $this->app->singleton('defender.user', function ($app) {
        $userModel = $app['config']->get('defender.user_model');

        return new EloquentUserRepository($app, $app->make($userModel));
    });

    ...
}

The $userModel creation follows the correct behavior, so should be the Role and Permission, but changing the logic throws the error:

 Type error: Argument 2 passed to Artesaos\Defender\Repositories\Eloquent\EloquentRoleRepository::__construct() must be an instance of Artesaos\Defender\Role

So, I believe one strategy would be to refactor the Role and Permission classes into traits to be used by necessary classes of the app or by default flat classes of the package. This, of course, needs to be better studied. Or a simpler aproach by changing the signature of the __construct functions of EloquentRoleRepository and EloquentPermissionRepository classes.

@nunomazer nunomazer changed the title Role and Permissions should be created based on config file Role and Permission should be created based on config file May 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants