code: private function selectRestVersion($channelXml, $supportedVersions)
      {
          $channelXml->registerXPathNamespace('ns', self::CHANNEL_NS);
  
          foreach ($supportedVersions as $version) {
              $xpathTest = "ns:servers/ns:*/ns:rest/ns:baseurl[@type='{$version}']";
              $testResult = $channelXml->xpath($xpathTest);
  
              foreach ($testResult as $result) {
                  // Choose first https:// option.
                  $result = (string) $result;
                  if (preg_match('{^https://}i', $result)) {
                      return array('version' => $version, 'baseUrl' => $result);
                  }
              }
  
              // Fallback to non-https if it does not exist.
              if (count($testResult) > 0) {
                  return array('version' => $version, 'baseUrl' => (string) $testResult[0]);
              }
          }
  
          return null;
      }
docs: Reads channel supported REST interfaces and selects one of them
  
  @param \SimpleXMLElement $channelXml
  @param string[] $supportedVersions supported PEAR REST protocols
  @return array|null hash with selected version and baseUrl