示例#1
0
 public static function generate($includeKey = false)
 {
     $guid = null;
     if (function_exists('com_create_guid')) {
         if ($includeKey) {
             $guid = com_create_guid();
         }
         return substr(com_create_guid(), 1, 36);
     } else {
         mt_srand((double) microtime() * 10000);
         //optional for php 4.2.0 and up.
         $charid = strtolower(md5(uniqid(rand(), true)));
         $hyphen = chr(45);
         // "-"
         $uuid = substr($charid, 0, 8) . $hyphen . substr($charid, 8, 4) . $hyphen . substr($charid, 12, 4) . $hyphen . substr($charid, 16, 4) . $hyphen . substr($charid, 20, 12);
         $guid = $includeKey == TRUE ? '{' . $uuid . '}' : $uuid;
     }
     return StringUtilsVTT::toUpperCase($guid);
 }
示例#2
0
 public static function arrayToXml(\SimpleXMLElement $object = null, $data = array())
 {
     foreach ($data as $key => $value) {
         if (is_object($value)) {
             $value = ArrayUtilsVTT::objectToArray($value);
         }
         if ($load = simplexml_load_string($value)) {
             $keyXMl = null;
             $doc = new \DOMDocument();
             $doc->loadXML($object->asXML());
             $appendXml = $doc->createDocumentFragment();
             $keyXMl = is_numeric($key) ? StringUtilsVTT::ToPluralString($load->children()->getName()) : $key;
             $stringXml = "<{$keyXMl}>";
             foreach ($load as $item) {
                 $stringXml .= $item->asXML();
             }
             $stringXml .= "</{$keyXMl}>";
             $appendXml->appendXML($stringXml);
             $doc->documentElement->appendChild($appendXml);
             $object = new \SimpleXmlElement($doc->saveXML());
             continue;
         }
         if (is_array($value)) {
             if (!is_numeric($key)) {
                 $new_object = $object->addChild($key);
             } else {
                 $new_object = $object->addChild($object->getName());
             }
             self::arrayToXml($new_object, $value, false);
         } else {
             if (!is_numeric($key)) {
                 $object->addChild($key, $value);
             } else {
                 $object->addChild($object->getName(), $value);
             }
         }
     }
     return $object;
 }