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

[Silber\Bouncer\Contracts\Clipboard] is not instantiable. (Non Laravel) #354

Closed
YuiLingo opened this issue Oct 1, 2018 · 7 comments
Closed

Comments

@YuiLingo
Copy link

YuiLingo commented Oct 1, 2018

May i know what reason cause the code below will throw [Silber\Bouncer\Contracts\Clipboard] is not instantiable exception.

require_once "./vendor/autoload.php";
require_once './Database.php';
require_once './User.php';

use Framework\Database as Database;
use Silber\Bouncer\Bouncer;
use App\Models\User;
new Database();


$user = User::find(1);
$bouncer = Bouncer::create($user);
$bouncer->useUserModel(User::class);

$admin = $bouncer->role()->firstOrCreate([
    'name' => 'admin',
    'title' => 'Administrator',
]);

$permissions = [
    [
        'name' => 'add-users',
        'title' => 'Add User',
    ],
    [
        'name' => 'edit-users',
        'title' => 'Edit User',
    ],
    [
        'name' => 'view-users',
        'title' => 'View User',
    ]
];
foreach($permissions as $index => $permission) {
    $ability = $bouncer->ability()->firstOrCreate($permission);
    $bouncer->allow($admin)->to($ability);
}
$user->assign('admin');

$abilities = $user->getAbilities();
var_dump($abilities->toArray());

But i change this use Silber\Bouncer\Contracts\Clipboard; to use Silber\Bouncer\Clipboard; in HasRoles.php then can run already. Means i need create a new HasRoles class for use?

@JosephSilber
Copy link
Owner

The clipboard contract is not bound in the container.

It should really be bound automatically. It's an oversight that it doesn't (when not used with Laravel). I'll fix it.

For now, you can bind it yourself:

use Silber\Bouncer\Contracts\Clipboard;

Container::getInstance()->instance(Clipboard::class, $bouncer->getClipboard());

@YuiLingo
Copy link
Author

YuiLingo commented Oct 5, 2018

The clipboard contract is not bound in the container.

It should really be bound automatically. It's an oversight that it doesn't (when not used with Laravel). I'll fix it.

For now, you can bind it yourself:

use Silber\Bouncer\Contracts\Clipboard;

Container::getInstance()->instance(Clipboard::class, $bouncer->getClipboard());

Thanks for reply. It works.

@YuiLingo YuiLingo closed this as completed Oct 5, 2018
@JosephSilber
Copy link
Owner

Keeping this open till I get to fix it.

@JosephSilber JosephSilber reopened this Oct 5, 2018
@YuiLingo
Copy link
Author

YuiLingo commented Oct 5, 2018

Keeping this open till I get to fix it.

Ok, Thanks.

@dbrw
Copy link

dbrw commented Oct 20, 2018

Hi, how about pimple? It doesn't have instance() method in it. This is what I have in my code:

$container[Silber\Bouncer\Contracts\Clipboard::class] = function($c) {
    return $c->get('bouncer')->getClipboard();
};

$container['bouncer'] = function($c) {
    $bouncer = Silber\Bouncer\Bouncer::create();
    $bouncer = $bouncer->useUserModel(App\Model\User::class);
    return $bouncer;
};

It was okay with rc-1.

@JosephSilber
Copy link
Owner

JosephSilber commented Oct 21, 2018

@dbrw If you're using Eloquent, you're already pulling in Laravel's container, so I'm not sure what you're asking, or why you'd need Pimple.

@JosephSilber
Copy link
Owner

I'm closing this for now, since the Factory class now registers the clipboard at the container.

@dbrw if you still need help with anything, feel free to open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants