Example #1
0
/**
 * iterate over the config xml
 *
 * @param SimpleXmlIterator $iterator  xml iterator
 * @param string            $parentKey parent of the current value of the iterator
 *
 * @return void
 */
function iterate($iterator, $parentKey)
{
    $db = Database::singleton();
    for ($iterator->rewind(); $iterator->valid(); $iterator->next()) {
        $current = $iterator->current();
        $name = $iterator->key();
        if ($iterator->hasChildren()) {
            iterate($current, $name);
        } else {
            // Else it is a leaf
            // If a key by that name exists, get its ID
            $configID = $db->pselectone("SELECT ID \n                 FROM ConfigSettings \n                 WHERE Name=:name", array('name' => $name));
            // If the key already exists
            if (!empty($configID)) {
                $dbParentKey = $db->pselectone("SELECT Name \n                     FROM ConfigSettings \n                     WHERE ID=(SELECT Parent FROM ConfigSettings WHERE Name=:name)", array('name' => $name));
                if ($parentKey == $dbParentKey) {
                    // Insert into the DB
                    processLeaf($name, $current, $configID);
                }
            }
        }
    }
}
 private function recursiveDeserialize(SimpleXmlIterator $xml_iterator)
 {
     $i = 0;
     $array = array();
     for ($xml_iterator->rewind(); $xml_iterator->valid(); $xml_iterator->next()) {
         if ($xml_iterator->hasChildren()) {
             if ($xml_iterator->current()->getName() == 'item') {
                 $array[$i++] = $this->recursiveDeserialize($xml_iterator->current());
             } else {
                 $array[Tools::strtolower($xml_iterator->key())] = $this->recursiveDeserialize($xml_iterator->current());
             }
         } else {
             if ($this->getAttributesValue('primitive', $xml_iterator->current()->attributes()) == 'array') {
                 $array[Tools::strtolower($xml_iterator->key())] = array();
             } elseif ($this->getAttributesValue('type', $xml_iterator->current()->attributes()) == 'binary') {
                 $array[Tools::strtolower($xml_iterator->key())] = mb_convert_encoding((string) $xml_iterator->current(), 'UTF-8', 'BASE64');
             } else {
                 $array[Tools::strtolower($xml_iterator->key())] = (string) $xml_iterator->current();
             }
         }
     }
     return $array;
 }
Example #3
0
 /**
  * @param \SimpleXmlIterator $sxi
  * @param null $key
  * @param null $tmp
  *
  * @return null
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since TODO Enter Product ${VERSION}
  */
 protected function sxiToXpath($sxi, $key = null, &$tmp = null)
 {
     $keys_arr = array();
     //get the keys count array
     for ($sxi->rewind(); $sxi->valid(); $sxi->next()) {
         $sk = $sxi->key();
         if (array_key_exists($sk, $keys_arr)) {
             $keys_arr[$sk] += 1;
             //					$keys_arr[ $sk ] = $keys_arr[ $sk ];
         } else {
             $keys_arr[$sk] = 1;
         }
     }
     //create the xpath
     for ($sxi->rewind(); $sxi->valid(); $sxi->next()) {
         $sk = $sxi->key();
         if (!isset(${$sk})) {
             ${$sk} = 1;
         }
         if ($keys_arr[$sk] >= 1) {
             $spk = $sk . '[' . ${$sk} . ']';
             $keys_arr[$sk] = $keys_arr[$sk] - 1;
             ${$sk}++;
         } else {
             $spk = $sk;
         }
         $kp = $key ? $key . '/' . $spk : '/' . $sxi->getName() . '/' . $spk;
         if ($sxi->hasChildren()) {
             $this->sxiToXpath($sxi->getChildren(), $kp, $tmp);
         } else {
             $tmp[$kp] = strval($sxi->current());
         }
         $at = $sxi->current()->attributes();
         if ($at) {
             $tmp_kp = $kp;
             foreach ($at as $k => $v) {
                 $kp .= '/@' . $k;
                 $tmp[$kp] = $v;
                 $kp = $tmp_kp;
             }
         }
     }
     return $tmp;
 }