Пример #1
0
 public function testToArray()
 {
     $array = array('level1' => array('Conjunction' => array('allowed' => true), 'Disjunction' => array('allowed' => false), 'Any' => array('allowed' => false), 'Negation' => array('allowed' => true)));
     $NC = new NestingConstraint();
     $NC->setLevel(1);
     $NC->addConnective('Conjunction', true);
     $NC->addConnective('Disjunction', false);
     $NC->addConnective('Any', false);
     $NC->addConnective('Negation', true);
     $this->assertEquals($array, $NC->toArray());
 }
Пример #2
0
 protected function parseNestingConstraints($maxLevels)
 {
     $array['constraints']['antecedent'] = array();
     $array['constraints']['consequent'] = array();
     $array['constraints']['condition'] = array();
     foreach ($this->XPath->evaluate('BuildingBlocks/DerivedBooleanAttribute/NestingConstraints') as $k => $elNcs) {
         $scope = $elNcs->getAttribute('scope');
         foreach ($this->XPath->evaluate('NestingConstraint', $elNcs) as $k => $elNc) {
             $NC = new NestingConstraint();
             $level = $elNc->getAttribute('level');
             foreach ($this->XPath->evaluate('Connectives/child::node()', $elNc) as $c) {
                 $allowed = $c->getAttribute('allowed') === 'yes';
                 $NC->addConnective($c->nodeName, $allowed);
             }
             if ($level === self::$CONSTRAINT_REMAINING) {
                 for ($i = $k + 1; $i <= $maxLevels; $i++) {
                     $NC->setLevel($i);
                     if ($scope === 'all') {
                         $array['constraints']['antecedent'] = array_merge_recursive($array['constraints']['antecedent'], $NC->toArray());
                         $array['constraints']['consequent'] = array_merge_recursive($array['constraints']['consequent'], $NC->toArray());
                         $array['constraints']['condition'] = array_merge_recursive($array['constraints']['condition'], $NC->toArray());
                     } else {
                         $array['constraints'][$scope] = array_merge_recursive($array['constraints'][$scope], $NC->toArray());
                     }
                 }
             } else {
                 $NC->setLevel($level);
                 if ($scope === 'all') {
                     $array['constraints']['antecedent'] = array_merge_recursive($array['constraints']['antecedent'], $NC->toArray());
                     $array['constraints']['consequent'] = array_merge_recursive($array['constraints']['consequent'], $NC->toArray());
                     $array['constraints']['condition'] = array_merge_recursive($array['constraints']['condition'], $NC->toArray());
                 } else {
                     $array['constraints'][$scope] = array_merge_recursive($array['constraints'][$scope], $NC->toArray());
                 }
             }
         }
     }
     return $array;
 }