/**
  * Get the repository XML as a string that can be returned to the browser or cached for future use.
  *
  * @param string|null $serverid      The server ID making the request, or null for anonymous.
  * @param string|null $limitPackager Limit the packager returned to at least version X.Y.
  * 
  * @return RepoXML
  */
 public static function GetAsRepoXML($serverid, $limitPackager)
 {
     $repo = new RepoXML();
     $repo->setDescription(ConfigHandler::Get('/package_repository/description'));
     $gpg = new Core\GPG\GPG();
     $keysfound = [];
     $where = [];
     if ($limitPackager) {
         $where[] = 'packager LIKE ' . $limitPackager . '%';
     }
     $packages = PackageRepositoryPackageModel::Find($where, null, 'type DESC, key ASC, version');
     foreach ($packages as $pkg) {
         /** @var PackageRepositoryPackageModel $pkg */
         $package = new PackageXML(null);
         $package->setType($pkg->get('type'));
         $package->setName($pkg->get('name'));
         $package->setVersion($pkg->get('version'));
         $package->setPackager($pkg->get('packager'));
         $package->setDescription($pkg->get('description'));
         $package->setKey($pkg->get('gpg_key'));
         if (!in_array($pkg->get('gpg_key'), $keysfound)) {
             $keysfound[] = $pkg->get('gpg_key');
         }
         $package->setFileLocation(\Core\resolve_link('/packagerepository/download?file=' . $pkg->get('file')));
         $upgrades = $pkg->get('requires');
         foreach ($upgrades as $dat) {
             $package->setRequire($dat['type'], $dat['name'], $dat['version'], $dat['operation']);
         }
         $upgrades = $pkg->get('provides');
         foreach ($upgrades as $dat) {
             $package->setProvide($dat['type'], $dat['name'], $dat['version']);
         }
         $upgrades = $pkg->get('upgrades');
         foreach ($upgrades as $dat) {
             $package->setUpgrade($dat['from'], $dat['to']);
         }
         $screens = $pkg->get('screenshots');
         foreach ($screens as $dat) {
             $f = \Core\Filestore\Factory::File($dat);
             $package->setScreenshot($f->getURL());
         }
         $package->setChangelog($pkg->get('changelog'));
         $repo->addPackage($package);
     }
     return $repo;
 }