コード例 #1
0
 /**
  * Init a arquive cache with $arquiveName name and $arquiveSize size
  * 
  * @param string  $arquiveName name for arquive cache (DEFAULT IS  emplexer_default_archive)
  * @param integer $arquiveSize size for arquive cache (DEFAULT IS 51200 Bytes)
  * @throws Exception if $arquiveSize is less or eguals zero 
  */
 private function __construct($arquiveName = 'emplexer_default_archive', $arquiveSize = 51200)
 {
     // hd_print(__METHOD__);
     $this->arquiveName = $arquiveName;
     if (!is_numeric($arquiveSize) || $arquiveSize <= 0) {
         throw new Exception("A bigger size is necessary to create an archive", 1);
     }
     $this->arquiveSize = $arquiveSize;
     ArchiveCache::set_archive($this);
 }
コード例 #2
0
 public static function get_archive($id, $url_prefix)
 {
     $archive = ArchiveCache::get_archive_by_id($id);
     if (!is_null($archive)) {
         return $archive;
     }
     $version_url = $url_prefix . '/versions.txt';
     try {
         $doc = HD::http_get_document($version_url);
     } catch (Exception $e) {
         $doc = null;
     }
     $version_by_name = array();
     $total_size = 0;
     if (is_null($doc)) {
         hd_print("Failed to fetch archive versions.txt from {$version_url}.");
     } else {
         $tok = strtok($doc, "\n");
         while ($tok !== false) {
             $pos = strrpos($tok, ' ');
             if ($pos === false) {
                 hd_print("Invalid line in versions.txt for archive '{$id}'.");
                 continue;
             }
             $name = trim(substr($tok, 0, $pos));
             $version = trim(substr($tok, $pos + 1));
             $version_by_name[$name] = $version;
             $tok = strtok("\n");
         }
         hd_print("Archive {$id}: " . count($version_by_name) . " files.");
         $size_url = $url_prefix . '/size.txt';
         $doc = HD::http_get_document($size_url);
         if (is_null($doc)) {
             hd_print("Failed to fetch archive size.txt from {$size_url}.");
             $version_by_name = array();
         } else {
             $total_size = intval($doc);
             hd_print("Archive {$id}: size = {$total_size}");
         }
     }
     $archive = new DefaultArchive($id, $url_prefix, $version_by_name, $total_size);
     ArchiveCache::set_archive($archive);
     return $archive;
 }