#Permissions and Roles
Last active
August 29, 2015 14:00
-
-
Save eseyden/11264316 to your computer and use it in GitHub Desktop.
Permissions and Roles
This file contains 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 | |
class adminRole { | |
} |
This file contains 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 | |
class basePermission { | |
protected $allowableRoles = array(); | |
function __construct(){ | |
$this->addRole(new adminRole()); | |
$this->addRole(new publicRole()); | |
$this->addRole(new userRole()); | |
} | |
function addRole($role){ | |
$found = false; | |
foreach($this->allowableRoles as $key => $allowableRole){ | |
if(get_class($allowableRole) === get_class($role)){ | |
$this->allowableRoles[$key] = $role; | |
$found = true; | |
} | |
} | |
if(!$found){ | |
$this->allowableRoles[] = $role; | |
} | |
} | |
function checkAccess(User $user){ | |
$has_access = false; | |
foreach($this->allowableRoles as $allowableRole){ | |
if($allowableRole->memberOf($user)){ | |
$has_access = true; | |
break; | |
} | |
} | |
return $has_access; | |
} | |
} |
This file contains 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 | |
class baseRole{ | |
function memberOf($user){ | |
/* | |
determine membership somehow | |
*/ | |
} | |
} |
This file contains 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 | |
class editThingsPermission extends basePermission{ | |
function __construct(){ | |
$this->allowableRoles = array(); | |
$this->addRole(new adminRole()); | |
} | |
} |
This file contains 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 | |
class publicRole extends baseRole{ | |
function checkAccess($user){ | |
return true; | |
} | |
} |
This file contains 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 | |
/** | |
* Created by PhpStorm. | |
* User: eseyden | |
* Date: 4/24/14 | |
* Time: 11:56 AM | |
*/ | |
class User { | |
} |
This file contains 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 | |
class userRole extends baseRole{ | |
public function checkAccess(User $user){ | |
foreach($user->adGroups as $adGroup){ | |
if($adGroup == 'App Users') return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment