Last active
September 19, 2015 16:11
-
-
Save crynobone/e46d22bbbbbe2c6bcda6 to your computer and use it in GitHub Desktop.
https://github.com/orchestral/authorization usage outside of Laravel or Orchestra Platform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "crynobone/standalone-authorization", | |
"type": "project", | |
"license": "MIT", | |
"authors": [ | |
{ | |
"name": "crynobone", | |
"email": "[email protected]" | |
} | |
], | |
"autoload": { | |
"classmap": [ | |
"UserRoles.php" | |
] | |
}, | |
"require": { | |
"orchestra/authorization": "~3.2" | |
}, | |
"minimum-stability": "dev" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require "vendor/autoload.php"; | |
$memory = new Orchestra\Memory\Provider(new Orchestra\Memory\Handlers\Runtime('app', [])); | |
$acl = new Orchestra\Authorization\Authorization('app', $memory); | |
$acl->setUser(new UserRoles(['Administrator', 'Editor'])); | |
$acl->roles()->attach(['Administrator', 'Editor', 'User']); | |
$acl->actions()->attach(['Manage User', 'Manage Post', 'Create Post', 'Edit Post']); | |
$acl->allow('Administrator', 'Manage User'); | |
$acl->allow(['Administrator', 'Editor'], 'Manage Post'); | |
$acl->allow('User', ['Create Post', 'Edit Post']); | |
echo $acl->can('Manage User') ? '✓ manage user' : '✗ manage user'; | |
echo PHP_EOL; | |
echo $acl->can('Manage Post') ? '✓ manage post' : '✗ manage post'; | |
echo PHP_EOL; | |
echo $acl->can('Create Post') ? '✓ create post' : '✗ create post'; | |
echo PHP_EOL; | |
echo $acl->can('Edit Post') ? '✓ edit post' : '✗ edit post'; | |
echo PHP_EOL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserRoles implements Orchestra\Contracts\Authorization\Authorizable | |
{ | |
protected $roles; | |
public function __construct(array $roles) | |
{ | |
$this->roles = $roles; | |
} | |
public function getRoles() | |
{ | |
return $this->roles; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment