public function testToArray()
 {
     $nested_options_list = Schema\OptionDefinitionList::create();
     $nested_options_list->add(Schema\OptionDefinition::create(array('value' => 'Nested Foobar One')));
     $list = Schema\OptionDefinitionList::create();
     $list->add(Schema\OptionDefinition::create(array('name' => 'Parent Foobar', 'value' => $nested_options_list)));
     $expected_list_array = array('Parent Foobar' => array('Nested Foobar One'));
     $this->assertSame($expected_list_array, $list->toArray());
 }
 protected function parseOption(\DOMXPath $xpath, \DOMElement $element)
 {
     $name = null;
     $value = null;
     $default = null;
     if ($element->hasAttribute('name')) {
         $name = $element->getAttribute('name');
     }
     $nested_options = $xpath->query('./option', $element);
     if ($nested_options->length > 0) {
         $value = Schema\OptionDefinitionList::create();
         foreach ($nested_options as $option_element) {
             $value->add($this->parseOption($xpath, $option_element));
         }
     } else {
         $value = trim($element->nodeValue);
     }
     return Schema\OptionDefinition::create(array('name' => $name, 'value' => $this->literalize($value), 'default' => $this->literalize($default)));
 }
Example #3
0
 protected function preRenderOptions(Schema\OptionDefinitionList $options, $initial_indent = 0, $indent_size = 4)
 {
     if ($options->getSize() === 0) {
         return 'array()';
     }
     $options_code = array('array(');
     $indent_spaces = str_repeat(" ", $initial_indent + $indent_size);
     $next_level_indent = $initial_indent + $indent_size;
     foreach ($options as $option) {
         $option_name = $option->getName();
         $option_value = $option->getValue();
         if ($option_name && $option_value instanceof Schema\OptionDefinitionList) {
             $options_code[] = sprintf("%s'%s' => %s,", $indent_spaces, $option_name, $this->preRenderOptions($option_value, $next_level_indent));
         } elseif ($option_value instanceof Schema\OptionDefinitionList) {
             $options_code[] = sprintf("%s%s,", $indent_spaces, $this->preRenderOptions($option_value, $next_level_indent));
         } elseif ($option_name) {
             $options_code[] = sprintf("%s'%s' => %s,", $indent_spaces, $option_name, var_export($option_value, true));
         } else {
             $options_code[] = sprintf("%s%s,", $indent_spaces, var_export($option_value, true));
         }
     }
     $options_code[] = sprintf('%s)', str_repeat(" ", $initial_indent));
     return implode(PHP_EOL, $options_code);
 }
Example #4
0
 public function __construct()
 {
     $this->fields = FieldDefinitionSet::create();
     $this->options = OptionDefinitionList::create();
 }