Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function set($groupRoleName, $superCategory, $category, Option $value)
 {
     $this->options[$groupRoleName][$superCategory][$category][$value->getName()] = $value;
     $categories = $this->optionData[$groupRoleName]->getCategories();
     foreach ($categories as $_category) {
         if ($_category->getName() != $superCategory) {
             continue;
         }
         $_categories = $_category->getCategories();
         foreach ($_categories as $__category) {
             if ($__category->getName() != $category) {
                 continue;
             }
             $_options = $__category->getOptions();
             foreach ($_options as $option) {
                 if ($option->getName() != $value->getName()) {
                     continue;
                 }
                 $option->setValue($value->getValue());
                 break 3;
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Converts the given values into options.
  *
  * @param string      $key
  * @param array|null  $values
  *
  * @return OptionCategory
  */
 private static function convertValues($key, $values)
 {
     $returnCategory = new OptionCategory();
     if ($values === null) {
         return $returnCategory;
     }
     if (self::isAssoc($values)) {
         $options = [];
         $categories = [];
         foreach ($values as $_key => $value) {
             // case: value = [...]
             if (is_array($value)) {
                 // recursive call
                 $subCategory = self::convertValues($_key, $value);
                 $subOptions = $subCategory->getOptions();
                 $subCategories = $subCategory->getCategories();
                 // case: value = [a, b, c]
                 if (count($subOptions) == 1 && empty($subCategories) && !self::isAssoc($value)) {
                     $options[] = $subOptions[0];
                     // case: value = [[a: b], [c: d, e: f]] || [a: b, c: d, e: [...]]
                 } else {
                     $category = new OptionCategory($_key);
                     $category->setOptions($subOptions);
                     $category->setCategories($subCategories);
                     $categories[] = $category;
                 }
                 // case: value = b
             } else {
                 $type = str_replace('double', 'float', gettype($value));
                 $type = str_replace('NULL', 'null', $type);
                 $options[] = new Option(0, $_key, $type, $value);
             }
         }
         $returnCategory->setOptions($options);
         $returnCategory->setCategories($categories);
     } else {
         $options = [];
         $_values = [];
         foreach ($values as $_key => $value) {
             if (is_array($value)) {
                 $subCategory = self::convertValues($_key, $value);
                 $subOptions = $subCategory->getOptions();
                 $subCategories = $subCategory->getCategories();
                 // case: value = [a: b]
                 if (count($subOptions) == 1 && empty($subCategories)) {
                     $option = $subOptions[0];
                     $options[] = $option;
                     // case: value = [a: b, d: e]
                 } elseif (count($subOptions) > 1) {
                     $option = new Option(0, '', 'array');
                     $optionValues = [];
                     foreach ($subOptions as $subOption) {
                         $optionValues[$subOption->getName()] = $subOption->getValue();
                     }
                     $option->setValue($optionValues);
                     $options[] = $option;
                 }
             } else {
                 $_values[] = $value;
             }
         }
         // case: values = [a, b, c, d]
         if (!empty($_values)) {
             $options[] = new Option(0, $key, 'array', $_values);
         }
         $returnCategory->setOptions($options);
     }
     return $returnCategory;
 }
Ejemplo n.º 3
0
 /**
  * Tests setting values.
  */
 public function testSet()
 {
     $option = new Option();
     // set name
     $option->setName('hero');
     $this->assertEquals('hero', $option->getName());
     $option->setName('');
     $this->assertEquals('', $option->getName());
     $option->setName('-123');
     $this->assertEquals('-123', $option->getName());
     // set type
     $option->setType('string');
     $this->assertEquals('string', $option->getType());
     $option->setType('boolean');
     $this->assertEquals('boolean', $option->getType());
     $option->setType('select');
     $this->assertEquals('select', $option->getType());
     // set value
     $option->setValue(123);
     $this->assertEquals(123, $option->getValue());
     $option->setValue(true);
     $this->assertTrue($option->getValue());
     $option->setValue('');
     $this->assertEquals('', $option->getValue());
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function set($optionCategory, $optionName, Option $value)
 {
     $this->optionsYAML[$optionCategory][$optionName] = $value->getValue();
 }