Example #1
0
 /**
  * Organizes an array of host keys to a map which is indexed by the host_key
  * value.
  *
  * NOTE: this function is made non-private so we can unit test it.
  *
  * @param array[int]array $urls
  * @return array[string]array
  */
 function hostkeysToHostKeyMap($urls)
 {
     $map = array();
     foreach ((array) $urls as $url) {
         // first canonicalize the URLs
         $canurl = GSB_UrlUtil::canonicalize($url);
         $phashes = GSB_UrlUtil::makePrefixesHashes($canurl['host'], $canurl['path'], $canurl['query'], $canurl['is_ip']);
         // make hostkeys
         $hostkeys = GSB_UrlUtil::makeHostKeyList($canurl['host'], $canurl['is_ip']);
         foreach ((array) $hostkeys as $hostkey) {
             $hostkey['url'] = $url;
             $hostkey['phashes'] = $phashes;
             $map[$hostkey['host_key']] = $hostkey;
         }
     }
     return $map;
 }