/** * @param SimpleXMLElement $fromXml * @param SimpleXMLElement $toXml * @param callable|null $substitutesFunction * @param string $keyAttribute */ private static function extendNodeAndChildren( SimpleXMLElement $fromXml, SimpleXMLElement $toXml, $substitutesFunction, $keyAttribute ) { if ( ! ( $fromXml->getName() === $toXml->getName() && $fromXml->attributes( $keyAttribute ) === $toXml->attributes( $keyAttribute ) ) ) { return; } foreach ( $fromXml->children() as $fromChild ) { if ( $fromChild->attributes( $keyAttribute ) !== null ) { $toChild = $toXml->getChildByNameAttr( $fromChild->getName(), $keyAttribute, $fromChild->attributes( $keyAttribute ) ); } elseif ( count( $fromChild->attributes() ) > 0 ) { $toChild = $toXml->getChildByNameAttributes( $fromChild->getName(), $fromChild->attributes() ); } elseif ( trim( $fromXml->data() ) != '' ) { $toChildren = $toXml->xpath( $fromXml->getName() . '[text()="' . addcslashes( $fromXml->data(), '"' ) . '"]' ); $toChild = ( count( $toChildren ) > 0 ) ? $toChildren[0] : null; } else { /* No attributes nor data: search single child with no attributes: */ $toChildren = $toXml->xpath( $fromChild->getName() . '[count(@*)=0]' ); if ( count( $toChildren ) == 1 ) { $toChild = $toChildren[0]; } else { /* No attributes nor data: search single child with attributes: */ $toChildren = $toXml->xpath( $fromChild->getName() ); if ( count( $toChildren ) == 1 ) { $toChild = $toChildren[0]; } else { $toChild = null; } } } if ( $toChild ) { self::extendNodeAndChildren( $fromChild, $toChild, $substitutesFunction, $keyAttribute ); continue; } $insertAfter = $fromChild->attributes( 'insert-node-after' ); if ( $insertAfter ) { $toChild = $toXml->getChildByNameAttr( $fromChild->getName(), $keyAttribute, $insertAfter ); if ( $toChild ) { $toChild->insertNodeAndChildrenAfter( $fromChild, $substitutesFunction ); } continue; } $insertBefore = $fromChild->attributes( 'insert-node-before' ); if ( $insertBefore ) { $toChild = $toXml->getChildByNameAttr( $fromChild->getName(), $keyAttribute, $insertBefore ); if ( $toChild ) { $toChild->insertNodeAndChildrenBefore( $fromChild, $substitutesFunction ); } continue; } $toXml->addChildWithDescendants( $fromChild, $substitutesFunction ); } }
/** * Converts an <option> to a stdClass db result * @param SimpleXMLElement $option * @return \stdClass */ protected function optionToSelObject(SimpleXMLElement $option) { $hasIndex = $option->attributes('index') !== '' && $option->attributes('index') !== null; $selObj = new \stdClass(); $selObj->value = $hasIndex ? $option->attributes('index') : $option->attributes('value'); if ($hasIndex) { $selObj->internalvalue = $option->attributes('value'); } $selObj->valuetype = $option->attributes('valuetype'); $selObj->operator = $option->attributes('operator'); $selObj->text = $option->data(); return $selObj; }