Ejemplo n.º 1
0
 protected function parseObj($obj)
 {
     if (!is_array($obj)) {
         return null;
     }
     $v = current($obj);
     $k = key($obj);
     $specs = [];
     if (is_array($v)) {
         foreach ($v as $item) {
             $ret = $this->parseObj($item);
             if ($ret) {
                 $specs[] = $ret;
             }
         }
     }
     switch ($k) {
         case 'and':
             $andSpec = new AndSpec();
             $andSpec->addMany($specs);
             return $andSpec;
         case 'or':
             $orSpec = new OrSpec();
             $orSpec->addMany($specs);
             return $orSpec;
         case 'not':
             return new NotSpec($this->parseObj($v));
         case 'lang':
         case 'e':
         case 'exp':
             return new ExpressionSpec($v);
             break;
         default:
             throw new UnknownSpec("Unknown spec: {$k}");
     }
 }
Ejemplo n.º 2
0
 public function testAddMany()
 {
     $chain = new AndSpec();
     $chain->addMany([new ExpressionSpec('1 == 1'), new ExpressionSpec('1 == 1')]);
     $this->assertEquals($chain->generate(), "(1 == 1 && 1 == 1)");
 }