Skip to content

Instantly share code, notes, and snippets.

@rizqidjamaluddin
Created December 4, 2014 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rizqidjamaluddin/51eb2065dffb584ab69a to your computer and use it in GitHub Desktop.
Save rizqidjamaluddin/51eb2065dffb584ab69a to your computer and use it in GitHub Desktop.
<?php
class NewsAuthorizer {
public function canPublish(Actor $user, NewsPost $post) {
// using different classes to the Actor interface?
return $user instanceof Editor;
// got more complex rules, like the user can only post news within their area of expertise?
return in_array($post->getSection()->getName(), $user->getAreasOfExpertise());
// not getting paid enough?
return rand(1,6) > 5;
// using an ACL system and users have roles?
return (new YourAclSystemOfChoice)->check($user->role(), 'create', 'post');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment