Skip to content

Instantly share code, notes, and snippets.

@jtallant
Last active February 12, 2016 23:05
Show Gist options
  • Save jtallant/6cba16a3caa18e0b3f15 to your computer and use it in GitHub Desktop.
Save jtallant/6cba16a3caa18e0b3f15 to your computer and use it in GitHub Desktop.
ACL Interface
<?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