<?php/** * @Title: class.access.php * @Author: Brendan Scarvell (xenoix) * @Note: * - Example on how to make a web based Active Directory web management with restrictions etc. * * @Todo: * - Make permissions and users to be stored in a database * - Add directories and "shares" for the users to inherit the permissions to**/abstract class user{ public function __construct($name) { $this->name = $name; } public function getName() { return $this->name; } // Permission Methods public static function hasReadPermission() { return true; } public static function hasModifyPermission() { return false; } public static function hasDeletePermission(){ return false; } // Customization methods public static function wantsFlashInterface() { return true; } protected $name = NULL;}class GuestUser extends User{ public static function hasModifyPermission() { return true; }}class CustomerUser extends User{ // nothing here at the momment}class AdminUser extends User{ public static function hasModifyPermission() { return true; } public static function hasDeletePermission() { return true; } public static function wantsFlashInterface() { return false; }}Class UserFactory{ private static $users = array("xenoix" => "admin", "reZo" => "guest", "ace" => "customer"); public static function Create($name) { if(!isset(self::$users[$name])){ // Error out user doesnt exist echo 'Error: User does not exist'; } switch(self::$users[$name]){ case 'guest': return new GuestUser($name); break; case 'customer': return new CustomerUser($name); break; case 'admin': return new AdminUser($name); break; default: // By default, return a guest user return new GuestUser($name); break; } }}function boolToStr($b){ $b = ($b == true) ? "Yes\n" : "No\n"; return $b;}function displayPermissions(User $obj){ echo "<br />" . $obj->getName() . "'s permissions:\n"; echo "<br />Read: " . boolToStr($obj->hasReadPermission()); echo "<br />Modify: " . boolToStr($obj->hasModifyPermission()); echo "<br />Delete:" . boolToStr($obj->hasDeletePermission() . "<br />");}function displayRequirements(User $obj){ if($obj->wantsFlashInterface()) { echo "<br />" . $obj->getName() . ' requires Flash'; }}$logins = array('xenoix','reZo','ace');foreach($logins as $login){ displayPermissions(UserFactory::Create($login)); displayRequirements(UserFactory::Create($login)); }?>