Home > develop, security > PHP Access Control List (ACL)

PHP Access Control List (ACL)

November 13th, 2008

PHP Access Control List (ACL)

I made this Access Control List for Functions:

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Author Albertux (Alberto Isaac Ayala Esquivias)
// E-mail: albertoi7@gmail.com
// Web: http://albertux.ayalasoft.com
// Class: Access Control List
 
class ACL {
	public $functions;
 
	public function acl_function($function,$status) {
		if (function_exists($function)) {
			if($status==0) {
				$this->functions[$function]=0;
			} else {
				$this->functions[$function]=1;
			}
		}
	}
 
	public function acl_methods_class($class,$value) {
		$class_methods = get_class_methods($class);
		foreach ($class_methods as $method_name) {
			$this->functions[$class.'::'.$method_name]=$value;
		}
	}
 
	public function acl_functions($functions) {
		foreach($functions as $function => $value) {
			$this->functions[$function]=$value;
		}
	}
 
	public function execute($function,$params=NULL)  {
		$output='';  
		if($this->functions[$function]==1) {
				$output = call_user_func_array($function, $params);
			} 
		return $output;
	}
}

HOWTO use:

$ACL = new ACL();
 
// Array Functions, 0 = don't execute, 1 = execute
$functions = array ("somefunction" => 0, "otherfunction" => 0, "anotherfunction" => 1);
 
// Add functions on ACL
$ACL->acl_functions($functions);
 
$params = array("param 1", "param 2", "param 3");
$ACL->execute('somefunction',$params); // don't execute because on functions array 'somefunction ' => 0
 
// Add or modify function access
$ACL->acl_function('somefunction',1);
$ACL->execute('somefunction',$params); // execute, now 'somefunction' => 1
 
// Put the functions of the class 
$ACL->acl_methods_class('SomeClass',1);
 
// Execute a method from class
$ACL->execute('SomeClass::demo', $params);

develop, security

  1. No comments yet.
  1. No trackbacks yet.