/** * createByXml * * @param \SimpleXmlElement $xml * @param \SplPriorityQueue $namespaces * * @return AbstractField */ public static function createByXml(\SimpleXmlElement $xml, \SplPriorityQueue $namespaces = null) { $type = XmlHelper::get($xml, 'type', 'text'); if (class_exists($type)) { $class = $type; } else { $class = static::findFieldClass($type, $namespaces); } if (!class_exists($class)) { // Fallback to TextField $class = static::$defaultNamespace . '\\TextField'; } return new $class($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); }
/** * Method to test def(). * * @return void * * @covers Windwalker\Dom\SimpleXml\XmlHelper::def */ public function testDef() { XmlHelper::def($this->xml, 'flower', 'rose'); XmlHelper::def($this->xml, 'name', 'Play'); $this->assertEquals('rose', XmlHelper::get($this->xml, 'flower')); $this->assertEquals('List', XmlHelper::get($this->xml, 'name')); }