Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. <?php
  2.  
  3. interface AccessControl
  4. {
  5. public function userCan($action);
  6. }
  7.  
  8. class BitmaskAccessControl implements AccessControl
  9. {
  10. public function userCan($action)
  11. {
  12. // bitmask comparison here based on $action
  13. // return bool
  14. }
  15. }
  16.  
  17. class SomeOtherAccessControl implements AccessControl
  18. {
  19. public function userCan($action)
  20. {
  21. // some other type of comparison you have implemented
  22. // that does not use bitmask
  23. // return bool
  24. }
  25. }
  26.  
  27. // When I ask for AccessControl give me the bitmask implementation
  28. $app->bind('AccessControl', 'BitmaskAccessControl');
  29.  
  30. // Later on you decide to use your new implementation
  31. // When I ask for AccessControl give me the other implementation
  32. $app->bind('AccessControl', 'SomeOtherAccessControl');
  33.  
  34. // Now none of your code other than
  35. // the one line above needs updated even when completely removing the bitmask stuff
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement