This repository has been archived by the owner on Feb 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 137
/
parseACL.php
52 lines (50 loc) · 1.43 KB
/
parseACL.php
1
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
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/*
// example:
$object = new parseObject();
$object->__set('hello','world');
// This instantiates a ACL object with NO rights!
$acl = new parseACL();
$acl->setPublicReadAccess(false);
$acl->setReadAccessForId('user_id',true);
$acl->setWriteAccessForRole('role_name',true);
$object->ACL($acl);
$object->save();
*/
class parseACL{
public $acl;
public function __construct(){
$this->acl = new stdClass();
}
private function setAccessForKey($access,$key,$bool){
if(!($access == 'read' || $access == 'write')) return;
if(is_object($this->acl)) $this->acl = array();
if($bool) $this->acl[$key][$access] = true;
else {
if(isset($this->acl[$key])){
unset($this->acl[$key][$access]);
if(sizeof($this->acl[$key]) == 0) unset($this->acl[$key]);
}
if(sizeof($this->acl) == 0) $this->acl = new stdClass();
}
}
public function setPublicReadAccess($bool){
$this->setAccessForKey('read','*',$bool);
}
public function setPublicWriteAccess($bool){
$this->setAccessForKey('write','*',$bool);
}
public function setReadAccessForId($userId,$bool){
$this->setAccessForKey('read',$userId,$bool);
}
public function setWriteAccessForId($userId,$bool){
$this->setAccessForKey('write',$userId,$bool);
}
public function setReadAccessForRole($role,$bool){
$this->setAccessForKey('read','role:'.$role,$bool);
}
public function setWriteAccessForRole($role,$bool){
$this->setAccessForKey('write','role:'.$role,$bool);
}
}
?>