Extends acl resources to support associated privileges.
More...
List of all members.
Public Member Functions |
| __construct ($resourceId, array $privileges=null, $label=null) |
| Sets the resource identifier, and optionally the privileges and label.
|
| addPrivilege ($privilege) |
| Add a privilege to this resource.
|
| getId () |
| Get the id of this resource.
|
| getLabel () |
| Get the label set for this resource.
|
| getPrivilege ($id) |
| Get a specific privilege associated with this resource.
|
| getPrivileges () |
| Get the privileges associated with this resource.
|
| hasPrivilege ($id) |
| Check if this resource has the named privilege.
|
| hasPrivileges () |
| Check if this resource has any privileges.
|
| normalizePrivilege ($privilege, $id=null) |
| Normalize mixed input to a identifiable privilege.
|
| removePrivilege ($id) |
| Remove a privilege from this resource.
|
| setLabel ($label) |
| Set the human-friendly label for this resource.
|
| setPrivileges (array $privileges=null) |
| Set the privileges associated with this resource.
|
Protected Attributes |
| $_label = null |
| $_privileges = array() |
| $_published = false |
Detailed Description
Extends acl resources to support associated privileges.
- Copyright:
- 2011-2012 Perforce Software. All rights reserved
- License:
- Please see LICENSE.txt in top-level folder of this distribution.
- Version:
- 2012.2/486814
Constructor & Destructor Documentation
P4Cms_Acl_Resource::__construct |
( |
$ |
resourceId, |
|
|
array $ |
privileges = null , |
|
|
$ |
label = null |
|
) |
| |
Sets the resource identifier, and optionally the privileges and label.
- Parameters:
-
string | $resourceId | the string-based id of this resource |
array | $privileges | optional - set of privileges for this resource |
string | $label | optional - human friendly label for this resource |
- Returns:
- void
Member Function Documentation
P4Cms_Acl_Resource::addPrivilege |
( |
$ |
privilege | ) |
|
Add a privilege to this resource.
- Parameters:
-
P4Cms_Acl_Privilege | array | string | $privilege | a privilege instance, an array of privilege information or a string-based privilege id. |
- Returns:
- P4Cms_Acl_Resource provides fluent interface.
- Exceptions:
-
InvalidArgumentException | if the given privilege is invalid. |
{
$privilege = $this->normalizePrivilege($privilege);
$privilege->setResource($this);
$this->_privileges[$privilege->getId()] = $privilege;
return $this;
}
P4Cms_Acl_Resource::getId |
( |
| ) |
|
Get the id of this resource.
- Returns:
- string|null the id of this resource, or null if none set.
{
return $this->getResourceId();
}
P4Cms_Acl_Resource::getLabel |
( |
| ) |
|
Get the label set for this resource.
Any macros in the label will be expanded automatically.
- Returns:
- string the label of this resource, or the id if no label is set.
{
$macro = new P4Cms_Filter_Macro(array('resource' => $this));
return $macro->filter($this->_label ?: $this->getId());
}
P4Cms_Acl_Resource::getPrivilege |
( |
$ |
id | ) |
|
Get a specific privilege associated with this resource.
- Parameters:
-
string | $id | the associated privilege to get |
- Returns:
- P4Cms_Acl_Privilege the specified privilege.
P4Cms_Acl_Resource::getPrivileges |
( |
| ) |
|
Get the privileges associated with this resource.
Each element in the privileges list is keyed on the privilege id. The element value is itself an array gauranteed to contain the id of the privilege. It may also contain a human-friendly label
- Returns:
- array the privileges defined for this resource.
p4cms.acl.<resource>.privileges Modify the passed resource, intended to allow subscribers to add/remove/modify the resource's privileges. The <resource> portion of the topic is the resource's ID. P4Cms_Acl_Resource $resource The resource to modify.
{
if (!$this->_published) {
$this->_published = true;
P4Cms_PubSub::publish(
'p4cms.acl.' . $this->getId() . '.privileges',
$this
);
}
return $this->_privileges;
}
P4Cms_Acl_Resource::hasPrivilege |
( |
$ |
id | ) |
|
Check if this resource has the named privilege.
- Parameters:
-
string | $id | the id of the privilege to check for. |
- Returns:
- bool true if the identified privilege exists on this resource.
{
return array_key_exists($id, $this->_privileges);
}
P4Cms_Acl_Resource::hasPrivileges |
( |
| ) |
|
Check if this resource has any privileges.
- Returns:
- bool true, if there are any privileges on this resource.
{
return !empty($this->_privileges);
}
P4Cms_Acl_Resource::normalizePrivilege |
( |
$ |
privilege, |
|
|
$ |
id = null |
|
) |
| |
Normalize mixed input to a identifiable privilege.
If a string is given, it will be taken to be the privilege id. If an array is given, it may contain:
id - the id of the privilege label - optional, human-friendly privilege label allow - default set of roles granted this privilege
If the optional id parameter is given, it will be set as the privilege id, but only if the privilege parameter is an array without an id element.
- Parameters:
-
mixed | $privilege | a privilege info array, string id, or instance. |
string | $id | optional - id of the privilege if not present in privilege. |
- Returns:
- P4Cms_Acl_Privilege the new privilege instance.
- Exceptions:
-
InvalidArgumentException | if we can't produce an identifable privilege. |
{
if (!$privilege instanceof P4Cms_Acl_Privilege) {
$privilege = P4Cms_Acl_Privilege::factory($privilege);
}
if (!$privilege->getId()) {
$privilege->setId($id);
}
if (!$privilege->getId()) {
throw new InvalidArgumentException(
"Cannot normalize input to an identifiable privilege."
);
}
return $privilege;
}
P4Cms_Acl_Resource::removePrivilege |
( |
$ |
id | ) |
|
Remove a privilege from this resource.
- Parameters:
-
string | $id | a string-based privilege id. |
- Returns:
- P4Cms_Acl_Resource provides fluent interface.
{
if ($this->hasPrivilege($id)) {
unset($this->_privileges[$id]);
}
return $this;
}
P4Cms_Acl_Resource::setLabel |
( |
$ |
label | ) |
|
Set the human-friendly label for this resource.
- Parameters:
-
string | $label | the label for this resource. |
- Returns:
- P4Cms_Acl_Resource provides fluent interface.
{
$this->_label = (string) $label;
}
P4Cms_Acl_Resource::setPrivileges |
( |
array $ |
privileges = null | ) |
|
Set the privileges associated with this resource.
- Parameters:
-
array | $privileges | the privileges to associate with this resource. each entry must be a privilege instance, an array of privilege information or a string-based privilege id. |
- Returns:
- P4Cms_Acl_Resource provides fluent interface.
- Exceptions:
-
InvalidArgumentException | if any of the privileges are invalid. |
{
$this->_privileges = array();
if (!$privileges) {
return $this;
}
foreach ($privileges as $key => $value) {
$this->addPrivilege(
$this->normalizePrivilege($value, $key)
);
}
return $this;
}
Member Data Documentation
P4Cms_Acl_Resource::$_label = null [protected] |
P4Cms_Acl_Resource::$_privileges = array() [protected] |
P4Cms_Acl_Resource::$_published = false [protected] |
The documentation for this class was generated from the following file: