/** * Method to test getAttributes(). * * @return void * * @covers Windwalker\Dom\SimpleXml\XmlHelper::getAttributes */ public function testGetAttributes() { $attributes = array(); foreach ($this->xml->attributes() as $name => $value) { $attributes[$name] = (string) $value; } $this->assertEquals($attributes, XmlHelper::getAttributes($this->xml)); }
/** * handleXml * * @param \SimpleXMLElement $xml * * @return void */ protected function handleXml(\SimpleXMLElement $xml) { $this->name = XmlHelper::get($xml, 'name'); $this->label = XmlHelper::get($xml, 'label'); $this->attributes = XmlHelper::getAttributes($xml); $form = $xml; $group = array(); while ($parent = $form->xpath('..')) { $parent = $parent[0]; $name = $parent->getName(); if ($name == 'fieldset') { $this->fieldset = $this->fieldset ?: (string) $parent['name']; } elseif ($name == 'group') { array_unshift($group, (string) $parent['name']); } $form = $parent; } $this->group = implode('.', $group); }
/** * prepareOptions * * @param string|\SimpleXMLElement $xml * @param Option[] $options * * @throws \InvalidArgumentException * @return void */ protected function handleOptions($xml, $options = array()) { if ($xml instanceof \SimpleXMLElement) { foreach ($xml->children() as $name => $option) { if ($option->getName() == 'optgroup') { foreach ($option->children() as $opt) { $attributes = XmlHelper::getAttributes($opt); $opt = new Option((string) $opt, XmlHelper::getAttribute($opt, 'value'), $attributes); $this->options[XmlHelper::getAttribute($option, 'label')][] = $opt; } } else { $attributes = XmlHelper::getAttributes($option); $option = new Option((string) $option, XmlHelper::getAttribute($option, 'value'), $attributes); $this->options[] = $option; } } } else { foreach ($options as $name => $option) { // If is array, means it is group if (is_array($option)) { foreach ($option as $opt) { if (!$opt instanceof Option) { throw new \InvalidArgumentException(sprintf('Please give me %s class as option, %s given.', 'Windwalker\\Html\\Option', get_class($opt))); } } } else { if (!$option instanceof Option) { throw new \InvalidArgumentException(sprintf('Please give me %s class as option, %s given.', 'Windwalker\\Html\\Option', get_class($option))); } } if (is_numeric($name)) { $this->options[] = $option; } else { $this->options[$name] = $option; } } } }