Exemple #1
0
 /**
  * @inheritDoc
  */
 protected function setUp()
 {
     parent::setUp();
     $this->context = new GenericContext(array('Namespaced' => array('Number' => new GenericProperty(array('type' => new NumberType())), 'String' => new GenericProperty(array('type' => new StringType())), 'DateType' => new GenericProperty(array('type' => new DateType())), 'BooleanType' => new GenericProperty(array('type' => new BooleanType())), 'ArrayType' => new GenericProperty(array('type' => new ArrayType())))));
     $this->context->setValue('Namespaced::Number', 2);
     $this->tree = new Tree(new Truth($this->context));
     $this->tree->setSegmentId(1);
     $this->tree->setSegmentName('Segment #1');
     $childArray = array();
     for ($i = 1; $i <= 3; ++$i) {
         if ($i !== 3) {
             $properties = new ArrayIterator(array('configValue' => $i));
             $condition = new Equals($this->context, 'Namespaced::Number', $properties);
             $segment = new Tree($condition);
             $segment->setSegmentId($i + 1);
             $segment->setSegmentName('Segment #' . ($i + 1));
         } else {
             $segment = new Tree(new Truth($this->context));
             $segment->setSegmentId(4);
             $segment->setSegmentName('Default');
         }
         $childArray[] = $segment;
     }
     $this->tree->setChildren($childArray);
 }
Exemple #2
0
 /**
  * Broke this out to more easily make it recursive
  * @param array $data
  * @param ContextInterface $context
  * @return Tree 
  */
 private function doBuild(array $data, ContextInterface $context)
 {
     $filter = new FilterFactory($context, $data['Condition']);
     $tree = new Tree($filter->build());
     $tree->setSegmentName($data['segmentName']);
     $tree->setSegmentId($data['segmentId']);
     if (is_array($data['children'])) {
         foreach ($data['children'] as $child) {
             $segment = $this->doBuild($child, $context);
             $segment->setParent($tree);
             $tree->addChild($segment);
         }
     }
     return $tree;
 }