示例#1
0
文件: xml.php 项目: pdelbar/onethree
 /**
  * Parse the given condition and return it
  *
  * @param DOMElement $element
  * @param string $name
  * @return One_Permission_Rule
  */
 protected static function parseCondition($element, $name = NULL)
 {
     $p = NULL;
     $xpath = new DOMXPath(self::$_dom);
     foreach (explode(':', 'rule:and:or') as $roa) {
         $curr = $xpath->query('./' . $roa, $element);
         if ($curr->length > 0) {
             $curr = $curr->item(0);
             if ($roa == 'and' || $roa == 'or') {
                 $p = new One_Permission_Rule_Joiner(array('type' => $roa, 'not' => $curr->getAttribute('not') == 'not' ? true : false));
                 $rules = $curr->getElementsByTagName('rule');
                 if ($rules->length > 0) {
                     foreach ($rules->childNodes as $rule) {
                         $a = array();
                         foreach ($rule->attributes as $attrName => $attrNode) {
                             $val = $attrNode->value;
                             if ($attrName == 'not') {
                                 $val = $val == 'not';
                             }
                             $a[$attrName] = $val;
                         }
                         $p->addRule(new One_Permission_Rule($rule));
                     }
                     unset($curr->rule);
                 }
                 $and = $curr->getElementsByTagName('and');
                 $or = $curr->getElementsByTagName('or');
                 if ($and->length > 0 || $or->length > 0) {
                     $p->addRule(self::parseCondition($curr));
                 }
             } else {
                 if ($roa == 'rule') {
                     $a = array();
                     foreach ($curr->attributes as $attrName => $attrNode) {
                         $val = $attrNode->value;
                         if ($attrName == 'not') {
                             $val = $val == 'not';
                         }
                         $a[$attrName] = $val;
                     }
                     $p = new One_Permission_Rule($a);
                 }
             }
         }
     }
     if (!is_null($name)) {
         One_Form_Factory::$_conditions[$name] = $p;
     }
     return $p;
 }
示例#2
0
文件: xml.php 项目: pdelbar/onethree
 /**
  * Parse conditions that are used to see whether you are allowed to perform certain actions on the scheme
  *
  * @param One_Scheme $scheme
  * @param DOMXPath $xpath
  * @param DOMElement $element
  * @param string $name name of the rule
  * @return One_Permission_Rule
  */
 protected static function parseCondition(One_Scheme $scheme, DOMXPath $xpath, DOMElement $element, $name = NULL)
 {
     foreach (array('rule', 'and', 'or') as $roa) {
         $currs = $xpath->query($element->getNodePath() . '/' . $roa);
         if ($currs->length > 0) {
             $curr = $currs->item(0);
             if ($roa == 'and' || $roa == 'or') {
                 $p = new One_Permission_Rule_Joiner(array('type' => $roa, 'not' => $curr->getAttribute('not') == 'not' ? true : false));
                 $rules = $curr->getElementsByTagName('rule');
                 if ($rules->length > 0) {
                     for ($i = 0; $i < $rules->length; $i++) {
                         $rule = $rules->item($i);
                         $p->addRule(new One_Permission_Rule(array('type' => $rule->getAttribute('type'), 'not' => $rule->getAttribute('not') == 'not' ? true : false)));
                     }
                     unset($rule);
                 }
                 if ($curr->getElementsByTagName('and')->length > 0 || $curr->getElementsByTagName('or')->length > 0) {
                     $p->addRule(self::parseCondition($curr, $scheme));
                 }
             } else {
                 if ($roa == 'rule') {
                     $p = new One_Permission_Rule(array('type' => $curr->getAttribute('type'), 'not' => $curr->getAttribute('not') == 'not' ? true : false));
                 }
             }
         }
     }
     if (!is_null($name)) {
         $tasks = explode(';', $name);
         foreach ($tasks as $task) {
             if (trim($task) != '') {
                 $scheme->addRule($task, $p);
             }
         }
     }
     return $p;
 }