本文整理汇总了PHP中Zend_Acl::setRule方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Acl::setRule方法的具体用法?PHP Zend_Acl::setRule怎么用?PHP Zend_Acl::setRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Acl
的用法示例。
在下文中一共展示了Zend_Acl::setRule方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _addRules
/**
* Method used to add rules to the specified resource.
*/
protected function _addRules($type = Zend_Acl::TYPE_ALLOW, array $rules, $resource, $resourceName)
{
foreach ($rules as $privilege => $ruleProperties) {
// If the user sets the privilege value to a string, we will consider
// this as the list of roles.
if (!is_array($ruleProperties)) {
$ruleProperties = array('roles' => $ruleProperties);
}
if ($privilege === 'all') {
$privilege = null;
}
$roles = $ruleProperties['roles'];
if (is_null($roles) || empty($roles)) {
$section = 'rules';
if ($type === Zend_Acl::TYPE_ALLOW) {
$section = 'allow ' . $section;
} else {
$section = 'deny ' . $section;
}
throw new Zend_Application_Resource_Exception(sprintf($this->_missingPropertyMessage, 'roles', $section, 'resource ' . $resourceName));
}
$roles = explode(',', $roles);
if ($roles[0] === 'all') {
$roles = null;
}
$assert = null;
if (isset($ruleProperties['assert']) && !empty($ruleProperties['assert'])) {
$assert = $ruleProperties['assert'];
$assert = new $assert();
}
$this->_acl->setRule(Zend_Acl::OP_ADD, $type, $roles, $resource, $privilege, $asset);
}
}
示例2: testSetRuleWorksWithResourceInterface
public function testSetRuleWorksWithResourceInterface()
{
$roleGuest = new Role\GenericRole('guest');
$this->_acl->addRole($roleGuest);
$resourceFoo = new Resource\GenericResource('foo');
$this->_acl->addResource($resourceFoo);
$this->_acl->setRule(Acl\Acl::OP_ADD, Acl\Acl::TYPE_ALLOW, $roleGuest, $resourceFoo);
}
示例3: buildAcl
public function buildAcl()
{
if ($this->_acl !== null) {
return $this->_acl;
}
$aclDefinition = Zym_Message_Dispatcher::get()->post('buildAcl')->getResult('buildAcl');
$acl = new Zend_Acl();
foreach ($aclDefinition as $module) {
if (!$acl->has($module['resource'])) {
$acl->addResource($module['resource']);
}
foreach ($module['rules'] as $key => $rule) {
if (!$acl->hasRole($key)) {
$acl->addRole($key);
}
$acl->setRule('OP_ADD', $rule['allPrivileges']['type'], $key, $module['resource']);
}
}
$this->_acl = $acl;
return $this->_acl;
}