/**
  * Parse a new Package object from a SimpleXMLElement.
  *
  * @param $log_pack  (Object) SimpleXMLElement node to be "parsed".
  * @return  (Object) Resultant Package object.
  */
 public static function newFromSimpleXMLElement(&$log_pack, $releaseType = 'unstable')
 {
     if (!$log_pack instanceof SimpleXMLElement) {
         throw new Exception('Received invalid log_pack');
     }
     $platformId = BuildRepositoryPlugin::parsePlatformId(clean_text($log_pack->platform));
     $cleanDirectDownloadUri = safe_url($log_pack->downloadUri);
     if (!empty($log_pack->downloadFallbackUri)) {
         $cleanDirectDownloadFallbackUri = safe_url($log_pack->downloadFallbackUri);
     } else {
         $cleanDirectDownloadFallbackUri = NULL;
     }
     if (!empty($log_pack->name)) {
         $name = clean_text($log_pack->name);
     } else {
         // We must resort to extracting the name from download Uri.
         $filename = basename(substr($cleanDirectDownloadUri, 0, -9));
         $filename = preg_replace(array('/-/', '/_/'), ' ', $filename);
         $words = explode(' ', substr($filename, 0, strrpos($filename, '.')));
         $name = ucwords(implode(' ', $words));
     }
     if (!empty($log_pack->version)) {
         $versionText = clean_text($log_pack->version);
         $version = Version::fromString($versionText);
     } else {
         $version = NULL;
     }
     // Determine package type.
     foreach ($log_pack->attributes() as $attrib => $value) {
         if ($attrib === 'type') {
             $type = $value;
         }
         break;
     }
     if (!isset($type)) {
         $type = 'distribution';
     }
     switch ($type) {
         case 'plugin':
             if ($releaseType === RT_STABLE) {
                 $pack = new PluginBuilderPackage($platformId, $name, $version, $cleanDirectDownloadUri, $cleanDirectDownloadFallbackUri);
             } else {
                 $pack = new PluginUnstableBuilderPackage($platformId, $name, $version, $cleanDirectDownloadUri, $cleanDirectDownloadFallbackUri);
             }
             break;
         default:
             if ($releaseType === RT_STABLE) {
                 $pack = new DistributionBuilderPackage($platformId, $name, $version, $cleanDirectDownloadUri, $cleanDirectDownloadFallbackUri);
             } else {
                 $pack = new DistributionUnstableBuilderPackage($platformId, $name, $version, $cleanDirectDownloadUri, $cleanDirectDownloadFallbackUri);
             }
             break;
     }
     if (!empty($log_pack->compileLogUri)) {
         $pack->setCompileLogUri(safe_url($log_pack->compileLogUri));
     }
     if (!empty($log_pack->compileWarnCount)) {
         $pack->setCompileWarnCount((int) $log_pack->compileWarnCount);
     }
     if (!empty($log_pack->compileErrorCount)) {
         $pack->setCompileErrorCount((int) $log_pack->compileErrorCount);
     }
     return $pack;
 }
 /**
  * Parse a new Commit record from a SimpleXMLElement.
  *
  * @param $log_commit  (Object) SimpleXMLElement node to be "parsed".
  * @return  (Array) Resultant Commit record.
  */
 private static function parseCommit(&$log_commit)
 {
     if (!$log_commit instanceof SimpleXMLElement) {
         throw new Exception('Received invalid log_pack');
     }
     $tags = array();
     foreach ($log_commit->children() as $child) {
         if ($child->getName() !== 'tags') {
             continue;
         }
         foreach ($child->children() as $grandchild) {
             if ($grandchild->getName() !== 'tag') {
                 continue;
             }
             $log_tag = $grandchild;
             $tag = clean_text((string) $log_tag);
             $attribs = array();
             foreach ($log_tag->attributes() as $key => $value) {
                 $attrib = clean_text($key);
                 if (strcasecmp($attrib, 'guessed') == 0) {
                     $value = clean_text($value);
                     $attribs[strtolower($attrib)] = (int) eval('return (' . $value . ');');
                 }
             }
             $tags[$tag] = $attribs;
         }
     }
     $commit = array('submitDate' => strtotime(clean_text($log_commit->submitDate)), 'author' => clean_text($log_commit->author), 'repositoryUri' => safe_url($log_commit->repositoryUrl), 'sha1' => substr(preg_replace('[^a-zA-Z0-9]', '', $log_commit->sha1), 0, 40), 'title' => clean_text($log_commit->title), 'message' => clean_text($log_commit->message), 'tags' => $tags);
     return $commit;
 }
 /**
  * Parse a new Addon from a SimpleXMLElement.
  *
  * @param $list_game  (Object) SimpleXMLElement node to be "parsed".
  * @return  (object) Resultant Addon object.
  */
 private static function parseAddon(&$list_addon)
 {
     if (!$list_addon instanceof SimpleXMLElement) {
         throw new Exception('Received invalid list_addon');
     }
     $title = clean_text($list_addon->title);
     $version = !empty($list_addon->version) ? clean_text($list_addon->version) : NULL;
     $downloadUri = !empty($list_addon->downloadUri) ? safe_url($list_addon->downloadUri) : NULL;
     $homepageUri = !empty($list_addon->homepageUri) ? safe_url($list_addon->homepageUri) : NULL;
     // Construct and configure a new Addon instance.
     $addon = new Addon($title, $version, $downloadUri, $homepageUri);
     foreach ($list_addon->attributes() as $key => $value) {
         $attrib = clean_text($key);
         $value = clean_text($value);
         $addon->setAttrib($attrib, (int) eval('return (' . $value . ');'));
     }
     if (!empty($list_addon->description)) {
         $addon->setDescription(clean_text($list_addon->description));
     }
     if (!empty($list_addon->notes)) {
         $addon->setNotes(clean_text($list_addon->notes));
     }
     return $addon;
 }