Created
September 26, 2015 14:33
-
-
Save enygma/e8c53e98c9bcc69a6d85 to your computer and use it in GitHub Desktop.
Testing out the policy sets for the PropAuth library - not exactly where I want it to be yet (a little clunky) but getting there
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_once 'vendor/autoload.php'; | |
use \Psecio\PropAuth\Enforcer; | |
use \Psecio\PropAuth\User; | |
use \Psecio\PropAuth\Policy; | |
use \Psecio\PropAuth\PolicySet; | |
//--------------------------- | |
$user = (object)[ | |
'username' => 'ccornutt', | |
'user_id' => 1 | |
]; | |
$post = (object)[ | |
'title' => 'Test Post #1', | |
'id' => 4321, | |
'user_id' => 1 | |
]; | |
//--------------------------- | |
$policy = new Policy(); | |
$policy | |
->hasUsername('ccornutt') | |
->can($post, function($user) { | |
return ($post->user_id === $user->id); | |
}); | |
$policySet = new PolicySet(); | |
$policySet->add('update-post', $policy); | |
$enforcer = new Enforcer($policySet); | |
/** | |
Returns true because our username is "ccornutt" and | |
the User's ID and the one on the post match | |
*/ | |
$result = $enforcer->allows('update-post', $user); | |
echo 'RESULT: '.var_export($result, true)."\n\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment