Exemplo n.º 1
0
 /**
  * Add/expend a field on this ValuesGroup and returns the object instance.
  *
  * The object instance is a ValuesBagBuilder (subset of ValuesBag), which
  * allows to add extra values to the field:
  *
  * ->field('name')
  *   ->addSimpleValue('my value')
  *   ->addSimpleValue('my value 2')
  * ->end() // return back to the ValuesGroup
  *
  * Tip! If the field already exists the existing is expended (values are added).
  * To force an overwrite of the existing field use `->field('name', true)` instead.
  *
  * @param string $name
  * @param bool   $forceNew
  *
  * @return ValuesBagBuilder
  */
 public function field($name, $forceNew = false)
 {
     if (!$forceNew && $this->valuesGroup->hasField($name)) {
         $valuesBag = $this->valuesGroup->getField($name);
     } else {
         $valuesBag = new ValuesBagBuilder($this);
         $this->valuesGroup->addField($name, $valuesBag);
     }
     return $valuesBag;
 }
Exemplo n.º 2
0
 private function processFields(\SimpleXMLElement $values, ValuesGroup $valuesGroup, $groupIdx, $level)
 {
     /** @var \SimpleXMLElement $element */
     foreach ($values->fields->children() as $element) {
         $fieldName = $this->getFieldName((string) $element['name']);
         $fieldConfig = $this->config->getFieldSet()->get($fieldName);
         if ($valuesGroup->hasField($fieldName)) {
             $this->valuesToBag($fieldConfig, $element, $valuesGroup->getField($fieldName), $groupIdx, $level);
         } else {
             $valuesGroup->addField($fieldName, $this->valuesToBag($fieldConfig, $element, new ValuesBag(), $groupIdx, $level));
         }
     }
 }
Exemplo n.º 3
0
 /**
  * {FieldIdentification ":" FieldValues}*.
  *
  * @param ValuesGroup $valuesGroup
  * @param int         $level
  * @param int         $groupIdx
  * @param bool        $inGroup
  */
 private function fieldValuesPairs(ValuesGroup $valuesGroup, $level = 0, $groupIdx = 0, $inGroup = false)
 {
     $groupCount = 0;
     while (null !== $this->lexer->lookahead) {
         switch ($this->lexer->lookahead['type']) {
             case Lexer::T_OPEN_PARENTHESIS:
             case Lexer::T_MULTIPLY:
                 $groupCount++;
                 $this->validateGroupsCount($groupIdx, $groupCount, $level);
                 $valuesGroup->addGroup($this->fieldGroup($level + 1, $groupCount - 1));
                 break;
             case Lexer::T_IDENTIFIER:
                 $fieldName = $this->getFieldName($this->fieldIdentification());
                 $fieldConfig = $this->config->getFieldSet()->get($fieldName);
                 if ($valuesGroup->hasField($fieldName)) {
                     $this->fieldValues($fieldConfig, $valuesGroup->getField($fieldName), $level, $groupIdx);
                 } else {
                     $valuesGroup->addField($fieldName, $this->fieldValues($fieldConfig, new ValuesBag(), $level, $groupIdx));
                 }
                 break;
             case $inGroup && Lexer::T_CLOSE_PARENTHESIS:
                 // Group closing is handled using the Group() method
                 break 2;
             default:
                 $this->syntaxError(['(', 'FieldIdentification']);
                 break;
         }
     }
 }
Exemplo n.º 4
0
 private function processFields(array $values, ValuesGroup $valuesGroup, $groupIdx, $level)
 {
     foreach ($values as $name => $value) {
         $fieldName = $this->getFieldName($name);
         $fieldConfig = $this->config->getFieldSet()->get($fieldName);
         $value = array_merge(['single-values' => [], 'excluded-values' => [], 'ranges' => [], 'excluded-ranges' => [], 'comparisons' => [], 'pattern-matchers' => []], $value);
         if ($valuesGroup->hasField($fieldName)) {
             $this->valuesToBag($fieldConfig, $value, $valuesGroup->getField($fieldName), $groupIdx, $level);
         } else {
             $valuesGroup->addField($fieldName, $this->valuesToBag($fieldConfig, $value, new ValuesBag(), $groupIdx, $level));
         }
     }
 }