/** * Method to add a child * * @param JMenuNode &$node The node to process * @param boolean $setCurrent True to set as current working node * * @return void */ public function addChild(JMenuNode &$node, $setCurrent = false) { $this->_current->addChild($node); if ($setCurrent) { $this->_current =& $node; } }
/** * Method to add a child * * @param array $node. * @param boolean $setCurrent * * @return mixed * * @since 11.1 */ function addChild(&$node, $setCurrent = false) { $this->_current->addChild($node); if ($setCurrent) { $this->_current = &$node; } }
/** * Method to add a child * * @param array &$node The node to process * @param boolean $setCurrent True to set as current working node * * @return mixed * * @since 11.1 */ public function addChild(&$node, $setCurrent = false) { JLog::add('JTree::addChild() is deprecated.', JLog::WARNING, 'deprecated'); $this->_current->addChild($node); if ($setCurrent) { $this->_current =& $node; } }
public function setUp() { $this->metadataFactory = $this->getMock(ClassMetadataFactory::class); $this->metadataFactory->method('hasMetadataFor')->will($this->returnValueMap([[DummyEntity::class, true], [DummyEmbeddable::class, true]])); $this->metadataFactory->method('getMetadataFor')->will($this->returnValueMap([[DummyEntity::class, DummyEntity::getMetadata()], [DummyEmbeddable::class, DummyEmbeddable::getMetadata()]])); $em = $this->getMock(EntityManagerInterface::class); $em->method('getMetadataFactory')->willReturn($this->metadataFactory); $this->entity = new DummyEntity(); $this->entity->setId(1); $this->entity->setA('1a'); $this->entity->setB('1b'); $this->entity->setC('1c'); $d = new DummyEmbeddable(); $d->setX(1); $d->setY(2); $d->setZ(3); $this->entity->setD($d); $child = new DummyEntity(); $child->setId(2); $child->setA('2a'); $child->setB('2b'); $child->setC('2c'); $d = new DummyEmbeddable(); $d->setX(21); $d->setY(22); $d->setZ(23); $child->setD($d); $this->entity->addChild($child); $child = new DummyEntity(); $child->setId(3); $child->setA('3a'); $child->setB('3b'); $child->setC('3c'); $d = new DummyEmbeddable(); $d->setX(31); $d->setY(32); $d->setZ(33); $child->setD($d); $this->entity->addChild($child); $subchild = new DummyEntity(); $subchild->setId(4); $subchild->setA('4a'); $subchild->setB('4b'); $subchild->setC('4c'); $d = new DummyEmbeddable(); $d->setX(41); $d->setY(42); $d->setZ(43); $subchild->setD($d); $child->addChild($subchild); $this->normalizer = new DoctrineNormalizer(null, null, null, $em); $propertyNormalizer = new PropertyNormalizer(); $serializer = new Serializer([$this->normalizer, $propertyNormalizer]); $this->normalizer->setSerializer($serializer); }
/** * Executes initialization actions required to setup the data structures * related to the tag. * <p> * This includes: * <ul> * <li>creation of the nested element</li> * <li>calling the setters for attributes</li> * <li>adding the element to the container object</li> * <li>adding a reference to the element (if id attribute is given)</li> * </ul> * * @param string the tag that comes in * @param array attributes the tag carries * @throws ExpatParseException if the setup process fails * @access public */ function init($propType, $attrs) { $configurator = $this->configurator; $project = $this->configurator->project; // introspect the parent class that is custom $parentClass = get_class($this->parent); $ih = IntrospectionHelper::getHelper($parentClass); try { if ($this->parent instanceof UnknownElement) { $this->child = new UnknownElement(strtolower($propType)); $this->parent->addChild($this->child); } else { $this->child = $ih->createElement($project, $this->parent, strtolower($propType)); } $configurator->configureId($this->child, $attrs); if ($this->parentWrapper !== null) { $this->childWrapper = new RuntimeConfigurable($this->child, $propType); $this->childWrapper->setAttributes($attrs); $this->parentWrapper->addChild($this->childWrapper); } else { $configurator->configure($this->child, $attrs, $project); $ih->storeElement($project, $this->parent, $this->child, strtolower($propType)); } } catch (BuildException $exc) { throw new ExpatParseException("Error initializing nested element <{$propType}>", $exc, $this->parser->getLocation()); } }
/** * Executes initialization actions required to setup the data structures * related to the tag. * <p> * This includes: * <ul> * <li>creation of the nested element</li> * <li>calling the setters for attributes</li> * <li>adding the element to the container object</li> * <li>adding a reference to the element (if id attribute is given)</li> * </ul> * * @param string the tag that comes in * @param array attributes the tag carries * @throws ExpatParseException if the setup process fails */ public function init($propType, $attrs) { $configurator = $this->configurator; $project = $this->configurator->project; try { $this->child = new UnknownElement(strtolower($propType)); $this->child->setTaskName($propType); $this->child->setTaskType($propType); $this->child->setProject($project); $this->child->setLocation($this->parser->getLocation()); if ($this->target !== null) { $this->child->setOwningTarget($this->target); } if ($this->parent !== null) { $this->parent->addChild($this->child); } elseif ($this->target !== null) { $this->target->addTask($this->child); } $configurator->configureId($this->child, $attrs); $this->childWrapper = new RuntimeConfigurable($this->child, $propType); $this->childWrapper->setAttributes($attrs); if ($this->parentWrapper !== null) { $this->parentWrapper->addChild($this->childWrapper); } } catch (BuildException $exc) { throw new ExpatParseException("Error initializing nested element <{$propType}>", $exc, $this->parser->getLocation()); } }
/** * * * * @param string $function Name function point for attribute name on entity wsdl:operation section Binding. * @return bool TRUE if entity Operation/Binding was created on WSDL, FALSE if not. */ private function setBinding_Operation($function) { if (!is_object($this->node_Binding)) { $this->errorMSG = "Error - XMLNodeObject Binding is null"; return false; } if (empty($function)) { $this->errorMSG = "Error - Operation Binding name function isn't defined"; return false; } try { $objOperation = $this->node_Binding->addChild("{$this->prefix_ns_wsdl}:operation", null, $this->ns_wsdl); $objOperation->addAttribute("name", $function); $objSOAP_Oper = $objOperation->addChild("{$this->prefix_ns_soap}:operation", null, $this->ns_soap); $objSOAP_Oper->addAttribute("soapAction", "{$this->targetNamespace}/{$function}"); $objSOAP_Oper->addAttribute("style", "document"); $objIN = $objOperation->addChild("{$this->prefix_ns_wsdl}:input", null, $this->ns_wsdl); $objOUT = $objOperation->addChild("{$this->prefix_ns_wsdl}:output", null, $this->ns_wsdl); $objIN_Body = $objIN->addChild("{$this->prefix_ns_soap}:body", null, $this->ns_soap); $objOUT_Body = $objOUT->addChild("{$this->prefix_ns_soap}:body", null, $this->ns_soap); $objIN_Body->addAttribute("use", "literal"); $objOUT_Body->addAttribute("use", "literal"); $objIN_Body->addAttribute("namespace", $this->targetNamespace); $objOUT_Body->addAttribute("namespace", $this->targetNamespace); } catch (Exception $ex) { $this->errorMSG = "Failed generate Operation Binding WSDL section " . $ex->getMessage(); return false; } return true; }
/** * Recursively generates a menu from the description. * * Helper function called from generateMenuBar. * * @param object $parent The parent menu or menu bar. * * @param array $description See generateMenuBar's $description parameter. * */ protected function generateMenu($parent, array $description) { foreach ($description as $itemDescription) { if (empty($itemDescription['routeParameters'])) { $itemDescription['routeParameters'] = array(); } if (empty($itemDescription['children'])) { $parent->addChild($itemDescription['label'], array('route' => $itemDescription['route'], 'routeParameters' => $itemDescription['routeParameters'], 'attributes' => array("data-dojo-type" => "dijit/MenuItem", "data-dojo-props" => $this->generateOnClickHandler($itemDescription['route'], $itemDescription['routeParameters'])))); } else { if (isset($itemDescription['route'])) { $newParent = $parent->addChild($itemDescription['label'], array('route' => $itemDescription['route'], 'routeParameters' => $itemDescription['routeParameters'], 'attributes' => array("data-dojo-type" => "dijit/PopupMenuItem", "data-dojo-props" => $this->generateOnClickHandler($itemDescription['route'], $itemDescription['routeParameters'])), 'childrenAttributes' => array('data-dojo-type' => 'dijit/DropDownMenu'))); } else { $newParent = $parent->addChild($itemDescription['label'], array('attributes' => array("data-dojo-type" => "dijit/PopupMenuItem"), 'childrenAttributes' => array('data-dojo-type' => 'dijit/DropDownMenu'))); } $this->generateMenu($newParent, $itemDescription['children']); } } }
/** * Add child with attributes to $xmlObject. * * @param array $attributes * @return void */ protected function addChildWithAttributes($attributes = array()) { $child = static::$xmlObject->addChild($this->child); foreach ($attributes as $key => $value) { $child->addAttribute($key, $value); } foreach ($this->new as $key => $value) { $child->addChild($key, $value); } }
/** * Recursively generates a menu from the description. * * Helper function called from generateMenuBar. * * @param object $parent The parent menu or menu bar. * * @param array $description See generateMenuBar's $description parameter. * */ protected function generateMenu($parent, array $description) { foreach ($description as $itemDescription) { if (empty($itemDescription['routeParameters'])) { $itemDescription['routeParameters'] = array(); } if (empty($itemDescription['children'])) { // submenus hijos $parent->addChild($itemDescription['label'], array('route' => $itemDescription['route'], 'routeParameters' => $itemDescription['routeParameters'], 'extras' => array('safe_label' => true), 'label' => $itemDescription['icon'], 'attributes' => array('class' => $itemDescription['class']))); } } }
/** * Добавление временного изображения, * когда, например, заполняются не все поля и шаг create ad * перезагружается. * * @param int $id - имя изображения */ public function set_temp_img($img_name, $img_w, $img_h) { if (isset($this->campaign->img_temp)) { $img_temp = $this->campaign->img_temp; $img_temp->attributes()->src = $img_name; $img_temp->attributes()->width = $img_w; $img_temp->attributes()->height = $img_h; } else { $img_temp = $this->campaign->addChild('img_temp'); $img_temp->addAttribute('src', $img_name); $img_temp->addAttribute('width', $img_w); $img_temp->addAttribute('height', $img_h); } }
/** * XML-интерфейс списка встречных заявок * по конкретной НОВОЙ заявке ВМ-идентификатора * * @param integer $queryId номер (id) новой заявки идентификатора wmid, * информацию по которой необходимо вернуть * @param integer $capitallerWmid ВМ-идентификатор капиталлера * @return object Объект ответа */ public function getListCounterOrders($queryId, $capitallerWmid = false) { $this->url = 'https://wm.exchanger.ru/asp/XMLWMList3Det.asp'; $this->buildObject(); $sign = $this->sign($this->wmid . $queryId); $this->xml->addChild('wmid', $this->wmid); $this->xml->addChild('signstr', $sign); $this->xml->addChild('queryid', $queryId); if ($capitallerWmid) { $this->xml->addChild('capitallerwmid', $capitallerWmid); } $this->run(); return $this->result; }
/** * Add row */ private function _add() { $data = $this->_data; $this->xml['lastID'] += 1; $row = $this->xml->addChild('row'); $row->addAttribute('id', $this->get_last_id()); foreach (get_object_vars($data) as $name => $value) { $type = $this->check_type($value); $value = $type == 'array' ? serialize($value) : $value; $field = $row->addChild('field', $value); $field->addAttribute('name', $name); $field->addAttribute('type', $type); } }
function addLogger($type, $mask = null, $config = array()) { // make child logger $child = $this->loggerFactory($type, $config); if (!empty($child)) { //set error level mask if (!empty($mask)) { $child->setMask($mask); } // add child to main composite logger $ret = $this->logger->addChild($child); } else { $ret = false; } //set hasChildren flag if ($ret == true) { $this->hasChildren = true; } else { return false; } }
/** * Recusively travserses through an array to propagate SimpleXML objects. * @param array $array the array to parse * @param object $xml the Simple XML object (must be at least a single empty node) * @return object the Simple XML object (with array objects added) * @author Ben Balter */ function object_to_xml($array, $xml) { /* * Array of keys that will be treated as attributes, not children. */ $attributes = array('id', 'number', 'label', 'prefix'); /* * Recursively loop through each item. */ foreach ($array as $key => $value) { /* * If this is a numbered array, grab the parent node to determine the node name. */ if (is_numeric($key)) { $key = 'unit'; } /* * If this is an attribute, treat as an attribute. */ if (in_array($key, $attributes)) { $xml->addAttribute($key, $value); } else { if (is_object($value) || is_array($value)) { $child = $xml->addChild($key); $child = object_to_xml($value, $child); } else { $xml->addChild($key, $value); } } } return $xml; }
/** * This function recursively handles a mixed message body * adding child tags where necessary. Note: arrays with * numerical indexs will result in tags called {key}_{index} * * @param mixed $mixed The mixed element to operate on * @param string $key The name to use for any non-associative array child tags * @param object $parent the parent tag * @return void */ private static function _xmlChildMixed($mixed, $key, &$parent) { if (is_array($mixed)) { foreach ($mixed as $k => $v) { if (is_int($k)) { $k = $key . '_' . $k; } $k = trim(preg_replace('/[^a-zA-Z_]+/imx', '_', $k), '_'); $k = strtolower($k); $state = is_array($v); $state <<= 1; $state |= empty($parent->{$k}); // is_array | empty switch ($state) { // not an array but parent is not empty case 0: $parent->{$k} = $v; break; // not an array and parent is emtpy // not an array and parent is emtpy case 1: $parent->addChild($k, $v); break; // is an array but parent is not empty // is an array but parent is not empty case 2: self::_xmlChildMixed($v, $k, $parent->{$k}); break; // is an array and parent is empty // is an array and parent is empty case 3: self::_xmlChildMixed($v, $k, $parent->addChild($k)); break; } } } else { if (empty($parent->{$key})) { $key = trim(preg_replace('/[^a-zA-Z_]+/imx', '_', $key), '_'); $key = strtolower($k); $parent->addChild($key, $mixed); } else { $parent->{$key} = $mixed; } } }
/** * Export User data as xml * * @return string|null */ public static function toXml() { if (!class_exists('SimpleXMLElement')) { throw new \Exception('SimpleXMLElement class not found'); } if (!is_object(static::$simpleXML)) { static::$simpleXML = new \SimpleXMLElement('<root/>'); } $data = static::getData(); if (is_array($data)) { foreach ($data as $field => $value) { static::$simpleXML->addChild($field, $value); } return static::$simpleXML->asXML(); } }
/** * Handles opening element tags. * * @access private * @param object $parser * @param string $name * @param array $attrs * @return void */ function xml_start_element($parser, $name, $attrs) { if (!isset($this->startElement)) { // This is the first element. Create it and set it // as the current element. $this->startElement = new XMLElement($name, $attrs); $this->currentElement =& $this->startElement; } else { // This is not the first element. Create a new one // set the current element as the parent and then // set the new element as the current element. $element = new XMLElement($name, $attrs); $this->currentElement->addChild($element); $this->currentElement =& $element; } }
/** * Method initXMLObject() * * Start a new XML structure for the requests * * @return void * @access private */ private function initXMLObject() { $this->xml = new SimpleXmlElement('<EnviarInstrucao></EnviarInstrucao>'); $this->xml->addChild('InstrucaoUnica'); }
/** * Recusively travserses through an array to propegate SimpleXML objects * @param array $array the array to parse * @param object $xml the Simple XML object (must be at least a single empty node) * @return object the Simple XML object (with array objects added) */ protected function object_to_xml($array, $xml) { //array of keys that will be treated as attributes, not children $attributes = array('id'); //recursively loop through each item foreach ($array as $key => $value) { //if this is a numbered array, //grab the parent node to determine the node name if (is_numeric($key)) { $key = 'result'; } //if this is an attribute, treat as an attribute if (in_array($key, $attributes)) { $xml->addAttribute($key, $value); //if this value is an object or array, add a child node and treat recursively } else { if (is_object($value) || is_array($value)) { $child = $xml->addChild($key); $child = $this->object_to_xml($value, $child); //simple key/value child pair } else { $xml->addChild($key, $value); } } } return $xml; }
/** * This function recursively handles a mixed message body * adding child tags where necessary. Note: arrays with * numerical indexs will result in tags called {key}_{index} * @param mixed $mixed The mixed element to operate on * @param string $key The name to use for any non-associative array child tags * @param object $parent the parent tag * @return void */ private static function _addMixed($mixed, $key, &$parent) { if (is_array($mixed)) { foreach ($mixed as $index => $mixedElement) { if (is_int($index)) { $index = $key . '_' . $index; } if (is_array($mixedElement)) { if (!empty($parent->{$index})) { $subParent = $parent->{$index}; } else { $subParent = $parent->addChild($index); } self::_addMixed($mixedElement, $key, $subParent); } else { if (!empty($parent->{$index})) { $parent->{$index} = $mixedElement; } else { $parent->addChild($index, $mixedElement); } } } } else { if (!empty($parent->{$key})) { $parent->{$key} = $mixed; } else { $parent->addChild($key, $mixed); } } }
/** * Method used to match images with detail page data * * @param object $xml XMl Object with detail property information * @param object $images XML Object with images * * @return object Propertybase data with images */ function __matchImagesForDetailPage($xml, $images) { $i = 0; /* Loop through all Images */ foreach ($images->InventoryImage__c as $image) { if ((string) $xml->Id == (string) $image->InventoryItemId__c) { $xml->addChild('InventoryImage__c'); $xml->InventoryImage__c[$i]->addChild('ExternalId__c', $image->ExternalId__c); $xml->InventoryImage__c[$i]->addChild('ThumbnailUrl__c', $image->ThumbnailUrl__c); $xml->InventoryImage__c[$i]->addChild('MidResUrl__c', $image->MidResUrl__c); $xml->InventoryImage__c[$i]->addChild('HighResUrl__c', $image->HighResUrl__c); $i++; } } return $xml; }
/** * 数据XML编码 * @param object $xml XML对象 * @param mixed $data 数据 * @param string $item 数字索引时的节点名称 * @return string */ protected static function data2xml($xml, $data, $item = 'item') { foreach ($data as $key => $value) { /* 指定默认的数字key */ is_numeric($key) && ($key = $item); /* 添加子元素 */ if (is_array($value) || is_object($value)) { $child = $xml->addChild($key); self::data2xml($child, $value, $item); } else { if (is_numeric($value)) { $child = $xml->addChild($key, $value); } else { $child = $xml->addChild($key); $node = dom_import_simplexml($child); $cdata = $node->ownerDocument->createCDATASection($value); $node->appendChild($cdata); } } } }
/** * Add children to a SimpleXMLelement * * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**> * @since 2.18.10 - 2013-09-04 * @param object $parent reference to a SimpleXMLelement node * @param string $name new element node name * @param string $type content type, subelement(-s) name * @param string $content new subelement content * @param array $params new element 'attributes' * @uses iCalUtilityFunctions::_duration2str() * @uses iCalUtilityFunctions::_geo2str2() * @uses iCalUtilityFunctions::$geoLatFmt * @uses iCalUtilityFunctions::$geoLongFmt * @return void */ function _addXMLchild(&$parent, $name, $type, $content, $params = array()) { static $fmtYmd = '%04d-%02d-%02d'; static $fmtYmdHis = '%04d-%02d-%02dT%02d:%02d:%02d'; /** create new child node */ $name = strtolower($name); $child = $parent->addChild($name); if (!empty($params)) { $parameters = $child->addChild('parameters'); foreach ($params as $param => $parVal) { if ('VALUE' == $param) { continue; } $param = strtolower($param); if ('x-' == substr($param, 0, 2)) { $p1 = $parameters->addChild($param); $p2 = $p1->addChild('unknown', htmlspecialchars($parVal)); } else { $p1 = $parameters->addChild($param); switch ($param) { case 'altrep': case 'dir': $ptype = 'uri'; break; case 'delegated-from': case 'delegated-to': case 'member': case 'sent-by': $ptype = 'cal-address'; break; case 'rsvp': $ptype = 'boolean'; break; default: $ptype = 'text'; break; } if (is_array($parVal)) { foreach ($parVal as $pV) { $p2 = $p1->addChild($ptype, htmlspecialchars($pV)); } } else { $p2 = $p1->addChild($ptype, htmlspecialchars($parVal)); } } } } // end if( !empty( $params )) if (empty($content) && '0' != $content || !is_array($content) && ('-' != substr($content, 0, 1) && 0 > $content)) { return; } /** store content */ switch ($type) { case 'binary': $v = $child->addChild($type, $content); break; case 'boolean': break; case 'cal-address': $v = $child->addChild($type, $content); break; case 'date': if (array_key_exists('year', $content)) { $content = array($content); } foreach ($content as $date) { $str = sprintf($fmtYmd, (int) $date['year'], (int) $date['month'], (int) $date['day']); $v = $child->addChild($type, $str); } break; case 'date-time': if (array_key_exists('year', $content)) { $content = array($content); } foreach ($content as $dt) { if (!isset($dt['hour'])) { $dt['hour'] = 0; } if (!isset($dt['min'])) { $dt['min'] = 0; } if (!isset($dt['sec'])) { $dt['sec'] = 0; } $str = sprintf($fmtYmdHis, (int) $dt['year'], (int) $dt['month'], (int) $dt['day'], (int) $dt['hour'], (int) $dt['min'], (int) $dt['sec']); if (isset($dt['tz']) && 'Z' == $dt['tz']) { $str .= 'Z'; } $v = $child->addChild($type, $str); } break; case 'duration': $output = 'trigger' == $name && FALSE !== $content['before'] ? '-' : ''; $v = $child->addChild($type, $output . iCalUtilityFunctions::_duration2str($content)); break; case 'geo': if (!empty($content)) { $v1 = $child->addChild('latitude', iCalUtilityFunctions::_geo2str2($content['latitude'], iCalUtilityFunctions::$geoLatFmt)); $v1 = $child->addChild('longitude', iCalUtilityFunctions::_geo2str2($content['longitude'], iCalUtilityFunctions::$geoLongFmt)); } break; case 'integer': $v = $child->addChild($type, (string) $content); break; case 'period': if (!is_array($content)) { break; } foreach ($content as $period) { $v1 = $child->addChild($type); $str = sprintf($fmtYmdHis, (int) $period[0]['year'], (int) $period[0]['month'], (int) $period[0]['day'], (int) $period[0]['hour'], (int) $period[0]['min'], (int) $period[0]['sec']); if (isset($period[0]['tz']) && 'Z' == $period[0]['tz']) { $str .= 'Z'; } $v2 = $v1->addChild('start', $str); if (array_key_exists('year', $period[1])) { $str = sprintf($fmtYmdHis, (int) $period[1]['year'], (int) $period[1]['month'], (int) $period[1]['day'], (int) $period[1]['hour'], (int) $period[1]['min'], (int) $period[1]['sec']); if (isset($period[1]['tz']) && 'Z' == $period[1]['tz']) { $str .= 'Z'; } $v2 = $v1->addChild('end', $str); } else { $v2 = $v1->addChild('duration', iCalUtilityFunctions::_duration2str($period[1])); } } break; case 'recur': $content = array_change_key_case($content); foreach ($content as $rulelabel => $rulevalue) { switch ($rulelabel) { case 'until': if (isset($rulevalue['hour'])) { $str = sprintf($fmtYmdHis, (int) $rulevalue['year'], (int) $rulevalue['month'], (int) $rulevalue['day'], (int) $rulevalue['hour'], (int) $rulevalue['min'], (int) $rulevalue['sec']) . 'Z'; } else { $str = sprintf($fmtYmd, (int) $rulevalue['year'], (int) $rulevalue['month'], (int) $rulevalue['day']); } $v = $child->addChild($rulelabel, $str); break; case 'bysecond': case 'byminute': case 'byhour': case 'bymonthday': case 'byyearday': case 'byweekno': case 'bymonth': case 'bysetpos': if (is_array($rulevalue)) { foreach ($rulevalue as $vix => $valuePart) { $v = $child->addChild($rulelabel, $valuePart); } } else { $v = $child->addChild($rulelabel, $rulevalue); } break; case 'byday': if (isset($rulevalue['DAY'])) { $str = isset($rulevalue[0]) ? $rulevalue[0] : ''; $str .= $rulevalue['DAY']; $p = $child->addChild($rulelabel, $str); } else { foreach ($rulevalue as $valuePart) { if (isset($valuePart['DAY'])) { $str = isset($valuePart[0]) ? $valuePart[0] : ''; $str .= $valuePart['DAY']; $p = $child->addChild($rulelabel, $str); } else { $p = $child->addChild($rulelabel, $valuePart); } } } break; case 'freq': case 'count': case 'interval': case 'wkst': default: $p = $child->addChild($rulelabel, $rulevalue); break; } // end switch( $rulelabel ) } // end foreach( $content as $rulelabel => $rulevalue ) break; case 'rstatus': $v = $child->addChild('code', number_format((double) $content['statcode'], 2, '.', '')); $v = $child->addChild('description', htmlspecialchars($content['text'])); if (isset($content['extdata'])) { $v = $child->addChild('data', htmlspecialchars($content['extdata'])); } break; case 'text': if (!is_array($content)) { $content = array($content); } foreach ($content as $part) { $v = $child->addChild($type, htmlspecialchars($part)); } break; case 'time': break; case 'uri': $v = $child->addChild($type, $content); break; case 'utc-offset': if (in_array(substr($content, 0, 1), array('-', '+'))) { $str = substr($content, 0, 1); $content = substr($content, 1); } else { $str = '+'; } $str .= substr($content, 0, 2) . ':' . substr($content, 2, 2); if (4 < strlen($content)) { $str .= ':' . substr($content, 4); } $v = $child->addChild($type, $str); break; case 'unknown': default: if (is_array($content)) { $content = implode('', $content); } $v = $child->addChild('unknown', htmlspecialchars($content)); break; } }
/** * @name constructXmlNode() * @access private * @internal Transforma arrays em XML a nível infinito * @author Davi Crystal * @param array $array * @param object $node */ private function constructXmlNode($array, $node) { // ITERA CADA ITEM DA ARRAY RECEBIDA foreach ($array as $key => $value) { // SE O VALOR FOR UMA NOVA ARRAY OU OBJETO, CHAMA A FUNÇÃO PARA CRIAÇÃO DE NÓS // ABAIXO DO NÓ ATUAL if (is_array($value) || is_object($value)) { // CASO A CHAVE NÃO SEJA UM NÚMERO DA ARRAY ADICIONA O NOVO NÓ if (!is_numeric($key)) { $newNode = $node->addChild($key); } else { // CASO A CHAVE SEJA UM NÚMERO DA ARRAY DEFINE C NOVO NÓ COMO O NÓ PAI $newNode = $node; } // INICIA A CONSTRUÇÃO DE UM NOVO NÓ FILHO $this->constructXmlNode($value, $newNode); // CASO O VALOR EXISTA E SEJA UM STRING, CRIA UM UM NOVO NÓ NO XML, EXISTEM VALORES DEFINIDOS COMO "0" } elseif ($value != "") { $node->addChild($key, htmlspecialchars($value)); } } }
/** * Turn an array into an XML document. Alternative to array_map magic. * * @access public * @param object $xml * @param array $array * @return object */ public static function buildXml(&$xml, $array) { if (is_array($array)) { foreach ($array as $key => $value) { // XML_NONE if (!is_array($value)) { $xml->addChild($key, $value); continue; } // Multiple nodes of the same name if (isset($value[0])) { foreach ($value as $kValue) { if (is_array($kValue)) { self::buildXml($xml, array($key => $kValue)); } else { $xml->addChild($key, $kValue); } } // XML_GROUP } else { if (isset($value['attributes'])) { if (is_array($value['value'])) { $node = $xml->addChild($key); self::buildXml($node, $value['value']); } else { $node = $xml->addChild($key, $value['value']); } if (!empty($value['attributes'])) { foreach ($value['attributes'] as $aKey => $aValue) { $node->addAttribute($aKey, $aValue); } } // XML_MERGE } else { if (isset($value['value'])) { $node = $xml->addChild($key, $value['value']); unset($value['value']); if (!empty($value)) { foreach ($value as $aKey => $aValue) { if (is_array($aValue)) { self::buildXml($node, array($aKey => $aValue)); } else { $node->addAttribute($aKey, $aValue); } } } // XML_OVERWRITE } else { $node = $xml->addChild($key); if (!empty($value)) { foreach ($value as $aKey => $aValue) { if (is_array($aValue)) { self::buildXml($node, array($aKey => $aValue)); } else { $node->addChild($aKey, $aValue); } } } } } } } } return $xml; }
/** * Adds a CDATA property to an XML document. * * @param string $name * Name of property that should contain CDATA. * @param string $value * Value that should be inserted into a CDATA child. * @param object $parent * Element that the CDATA child should be attached too. */ function addCdata($name, $value, &$parent) { $child = $parent->addChild($name); if ($child !== NULL) { $child_node = dom_import_simplexml($child); $child_owner = $child_node->ownerDocument; $child_node->appendChild($child_owner->createCDATASection($value)); } return $child; }
/** * Function to delete wpc-client * * @param array $settings_array array of wp-client plugin settings. * @param object $xml_info object of new *.xml file. */ function acc_array_to_xml($settings_array, &$xml_info) { foreach ($settings_array as $key => $value) { if (is_array($value)) { if (range(0, count($value) - 1) == array_keys($value)) { $arrays = 0; foreach ($value as $not_range_value) { if (is_array($not_range_value)) { $arrays++; } } if (0 == $arrays) { $not_range_string = implode('#|#', $value); $xml_info->addChild("{$key}", "{$not_range_string}"); } else { $subnode = $xml_info->addChild("{$key}"); $this->acc_array_to_xml($value, $subnode); } } else { if (!is_numeric($key)) { $subnode = $xml_info->addChild("{$key}"); $this->acc_array_to_xml($value, $subnode); } else { $this->acc_array_to_xml($value, $xml_info); } } } else { $xml_info->addChild("{$key}", "{$value}"); } } }
/** * helper method to automatically create cdata section for a given value * * note: assuming all array values are already utf-8 encoded * * @param string $key Name of the text node * @param string $value Content of the text node * @param object $xml SimpleXMLElement to add text node to * * @return object */ private static function _processValue($key, $value, $xml) { $node = null; if (!is_string($value) && !is_numeric($value)) { // true false null object etc if ($value == true) { $node = $xml->addChild($key, 1); } else { $node = $xml->addChild($key, 0); } return $node; } $res = htmlentities($value); if ($res != $value) { // has special character // use dom to add a cdata section // note: ]]> will be escaped by createCDATASection() $node = dom_import_simplexml($xml); $owner = $node->ownerDocument; $elem = $owner->createElement($key); $cdata = $owner->createCDATASection($value); $elem->appendChild($cdata); $node->appendChild($elem); $node = simplexml_import_dom($elem); } else { $node = $xml->addChild($key, $value); } return $node; }