コード例 #1
0
 /**
  * For a given collection of users/groups/roles, get the permission
  * descriptor object that describes that exact collection, creating
  * such an object if it does not already exist.
  */
 function getOrCreateDescriptor($aAllowed)
 {
     $sDescriptor = KTPermissionUtil::generateDescriptor($aAllowed);
     $oDescriptor =& KTPermissionDescriptor::getByDescriptor(md5($sDescriptor));
     if (PEAR::isError($oDescriptor)) {
         $oOriginalDescriptor = $oDescriptor;
         $oDescriptor =& KTPermissionDescriptor::createFromArray(array("descriptortext" => $sDescriptor));
         if (PEAR::isError($oDescriptor)) {
             print '<pre>';
             print_r($aAllowed);
             print "-----------\n";
             print "getOrCreateDescriptor get error (should be 'not found'):";
             print "-----------\n";
             print_r($oOriginalDescriptor);
             print "-----------\n";
             print "getOrCreateDescriptor create error (should not happen):";
             print "-----------\n";
             print_r($oDescriptor);
             print '</pre>';
             exit(0);
         }
         $oDescriptor->saveAllowed($aAllowed);
     }
     return $oDescriptor;
 }
コード例 #2
0
<?php

require_once "../../config/dmsDefaults.php";
require_once KT_LIB_DIR . "/permissions/permissionutil.inc.php";
error_reporting(E_ALL);
$aAllowed = array("group" => array(1, 2, 3, 4), "user" => array(1, 2, 3, 4), "role" => array(1, 2, 3, 4));
var_dump(KTPermissionUtil::generateDescriptor($aAllowed));
$aAllowed = array("role" => array(4, 3, 2, 1), "group" => array(1, 3, 2, 4), "user" => array(2, 3, 1, 4));
var_dump(KTPermissionUtil::generateDescriptor($aAllowed));