forked from cihadoge/parse-php-sdk-for-codeigniter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseRole.php
More file actions
103 lines (92 loc) · 2.04 KB
/
Copy pathParseRole.php
File metadata and controls
103 lines (92 loc) · 2.04 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* ParseRole - Representation of an access Role.
*
* @package Parse
* @author Fosco Marotto <fjm@fb.com>
*/
class ParseRole extends ParseObject
{
public static $parseClassName = "_Role";
/**
* Create a ParseRole object with a given name and ACL.
*
* @param string $name
* @param ParseACL $acl
*
* @return ParseRole
*/
public static function createRole($name, ParseACL $acl)
{
$role = ParseObject::create(static::$parseClassName);
$role->setName($name);
$role->setACL($acl);
return $role;
}
/**
* Returns the role name.
*
* @return string
*/
public function getName()
{
return $this->get("name");
}
/**
* Sets the role name.
*
* @param string $name The role name
*
* @return null
*/
public function setName($name)
{
if ($this->getObjectId()) {
throw new ParseException(
"A role's name can only be set before it has been saved."
);
}
if (!is_string($name)) {
throw new ParseException(
"A role's name must be a string."
);
}
return $this->set("name", $name);
}
/**
* Gets the ParseRelation for the ParseUsers which are direct children of
* this role. These users are granted any privileges that this role
* has been granted.
*
* @return ParseRelation
*/
public function getUsers()
{
return $this->getRelation("users");
}
/**
* Gets the ParseRelation for the ParseRoles which are direct children of
* this role. These roles' users are granted any privileges that this role
* has been granted.
*
* @return ParseRelation
*/
public function getRoles()
{
return $this->getRelation("roles");
}
public function save($useMasterKey = false)
{
if (!$this->getACL()) {
throw new ParseException(
"Roles must have an ACL."
);
}
if (!$this->getName() || !is_string($this->getName())) {
throw new ParseException(
"Roles must have a name."
);
}
return parent::save($useMasterKey);
}
}