コード例 #1
0
ファイル: acl.php プロジェクト: ItsHaden/epicLanBootstrap
 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
0
ファイル: acl.php プロジェクト: binarygeotech/burgers
<?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