Last active
February 12, 2016 23:05
-
-
Save jtallant/6cba16a3caa18e0b3f15 to your computer and use it in GitHub Desktop.
ACL Interface
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 | |
interface AccessControl | |
{ | |
public function userCan($action); | |
} | |
class BitmaskAccessControl implements AccessControl | |
{ | |
public function userCan($action) | |
{ | |
// bitmask comparison here based on $action | |
// return bool | |
} | |
} | |
class SomeOtherAccessControl implements AccessControl | |
{ | |
public function userCan($action) | |
{ | |
// some other type of comparison you have implemented | |
// that does not use bitmask | |
// return bool | |
} | |
} | |
// When I ask for AccessControl give me the bitmask implementation | |
$app->bind('AccessControl', 'BitmaskAccessControl'); | |
// Later on you decide to use your new implementation | |
// When I ask for AccessControl give me the other implementation | |
$app->bind('AccessControl', 'SomeOtherAccessControl'); | |
// Now none of your code other than | |
// the one line above needs updated even when completely removing the bitmask stuff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment