本文整理汇总了PHP中ACL::save方法的典型用法代码示例。如果您正苦于以下问题:PHP ACL::save方法的具体用法?PHP ACL::save怎么用?PHP ACL::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACL
的用法示例。
在下文中一共展示了ACL::save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
public static function update()
{
$classes = array();
$dirs = array('core/controllers', 'core/controllers/admin');
foreach ($dirs as $dir) {
$files = scandir($dir);
foreach ($files as $file) {
$file = "{$dir}/{$file}";
if (pathinfo($file, PATHINFO_EXTENSION) == "php") {
require_once $file;
$data = file_get_contents($file);
preg_match('/class (?P<class>.+) extends /', $data, $matches);
if (isset($matches['class'])) {
$classes[] = $matches['class'];
}
}
}
}
$ignoreMethods = array('__construct', 'exec', 'getRule');
foreach ($classes as $class) {
$acl = new ACL();
$acl->controller = $class;
$acl->action = '';
$acl->save();
// Now every public method in this class
$methods = get_class_methods($class);
foreach ($methods as $method) {
if (!in_array($method, $ignoreMethods)) {
$acl = new ACL();
$acl->controller = $class;
$acl->action = $method;
$acl->save();
}
}
}
}
示例2: Test
<?php
$f3 = (require 'lib/base.php');
$f3->set("AUTOLOAD", "../lib");
$test = new Test();
$instance = new ACL(new DB\SQL("sqlite:/tmp/test.sqlite"));
$acl = new ACL(new DB\SQL("sqlite:/tmp/test.sqlite"));
$instance->action = "Node";
$instance->rule = ACL_READ + ACL_EDIT;
$instance->groupId = 1;
$instance->save();
$test->expect($instance->_id > 0, "ACL was saved.");
$instance->load(array("id = ?", $instance->_id));
$test->expect($acl->check(1, "Node", ACL_READ), "Have the right to Read");
$test->expect($acl->check(1, "Node", ACL_EDIT), "Have the right to Edit");
$test->expect(!$acl->check(1, "Node", ACL_CREATE), "Have not the right to Create");
$test->expect(!$acl->check(1, "Node", ACL_DELETE), "Have not the right to Delete");
try {
$acl->check(2, "Node", ACL_READ);
$test->expect(false, "Get an Exception for asking a wrong groupId");
} catch (Exception $e) {
$test->expect(true, "Get an Exception for asking a wrong groupId");
}
try {
$acl->check(1, "Apples", ACL_READ);
$test->expect(false, "Get an Exception for asking a wrong action");
} catch (Exception $e) {
$test->expect(true, "Get an Exception for asking a wrong action");
}
$test->expect($instance->erase(), "ACL was deleted.");
// Display the results; not MVC but let's keep it simple