Skip to content

Instantly share code, notes, and snippets.

@rizqidjamaluddin
Created November 17, 2014 13:19
Show Gist options
  • Save rizqidjamaluddin/b83048787a2d408511bb to your computer and use it in GitHub Desktop.
Save rizqidjamaluddin/b83048787a2d408511bb to your computer and use it in GitHub Desktop.
<?php
class BlogPostCommentAuthorizer {
public function can ($user, $blogPost, $comment) {
$judge = new Judge;
// blog post owner is obviously allowed to comment for sure
$policy = new EqualityPolicy();
$judge->consider($policy->enforce($user->id, $blogPost->getOwner()->id));
// ACL option. the list would generally be put in a separate file/config
$policy = new ACLPolicy(['mod' => '*', 'user' => 'read, post, edit, delete']);
// enforce would internally return a Vote class which contains the policy's response to the query
$judge->consider($policy->enforce($user->getRole(), 'post'));
return $judge->decide();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment