Changeset 49 for trunk

Show
Ignore:
Timestamp:
19.10.2005 19:06:23 (3 years ago)
Author:
m
Message:

Closes #4. Raise an error in File_Bittorrent_MakeTorrent if no file is given. Save last PEAR_Error object in public property.

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/File/Bittorrent/Decode.php

    r48 r49  
    145145 
    146146    /** 
     147    * @var mixed    The last error object or null if no error has occurred. 
     148    */ 
     149    var $last_error; 
     150 
     151    /** 
    147152    * Decode a Bencoded string 
    148153    * 
     
    168173        // Check file 
    169174        if (!is_file($file)) { 
    170             PEAR::raiseError('File_Bittorrent_Decode::decode() - Not a file.', null, null, "Given filename '$file' is not a valid file."); 
     175            $this->last_error = PEAR::raiseError('File_Bittorrent_Decode::decode() - Not a file.', null, null, "Given filename '$file' is not a valid file."); 
    171176            return false; 
    172177        } 
     
    190195        $decoded = $this->_bdecode(); 
    191196        if (!is_array($decoded)) { 
    192             PEAR::raiseError('File_Bittorrent_Decode::decode() - Corrupted bencoded data.', null, null, "Failed to decode data from file '$file'."); 
     197            $this->last_error = PEAR::raiseError('File_Bittorrent_Decode::decode() - Corrupted bencoded data.', null, null, "Failed to decode data from file '$file'."); 
    193198            return false; 
    194199        } 
     
    409414        // Check if we can access remote data 
    410415        if (!ini_get('allow_url_fopen')) { 
    411             PEAR::raiseError('File_Bittorrent_Decode::getStats() - "allow_url_fopen" must be enabled.'); 
     416            $this->last_error = PEAR::raiseError('File_Bittorrent_Decode::getStats() - "allow_url_fopen" must be enabled.'); 
    412417            return false; 
    413418        } 
     
    418423        $stats = $this->decode($scrape_data); 
    419424        if (!isset($stats['files'][$packed_hash])) { 
    420             PEAR::raiseError('File_Bittorrent_Decode::getStats() - Invalid scrape data: "' . $scrape_data . '"'); 
     425            $this->last_error = PEAR::raiseError('File_Bittorrent_Decode::getStats() - Invalid scrape data: "' . $scrape_data . '"'); 
    421426            return false; 
    422427        } 
  • trunk/File/Bittorrent/MakeTorrent.php

    r42 r49  
    134134 
    135135    /** 
     136    * @var mixed    The last error object or null if no error has occurred. 
     137    */ 
     138    var $last_error; 
     139 
     140    /** 
    136141     * Constructor 
    137142     * 
     
    169174    { 
    170175        if (!is_array($announce_list)) { 
    171             PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - No array given.'); 
     176            $this->last_error = PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - No array given.'); 
    172177            return false; 
    173178        } 
     
    223228    { 
    224229        if ($piece_length < 32 or $piece_length > 4096) { 
    225             PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - Invalid piece lenth: "' . $piece_length . '"'); 
     230            $this->last_error = PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - Invalid piece lenth: "' . $piece_length . '"'); 
    226231            return false; 
    227232        } 
     
    251256            } 
    252257            $metainfo = $this->_encodeTorrent(); 
     258        } else { 
     259            $this->last_error = PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - You must provide a file or directory.'); 
     260            return false; 
    253261        } 
    254262        return $metainfo; 
     
    277285            $bencdata['info']['files'] = $this->_files; 
    278286        } else { 
    279             PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - Use ' .  __CLASS__ . '::setPath() to define a file or directory.'); 
     287            $this->last_error = PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - Use ' .  __CLASS__ . '::setPath() to define a file or directory.'); 
    280288            return false; 
    281289        } 
     
    303311    function _addFile($file) 
    304312    { 
    305         if (!$this->_openFile($file)) return false; 
     313        if (!$this->_openFile($file)) { 
     314            $this->last_error = PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . "() - Failed to open file '$file'."); 
     315            return false; 
     316        } 
    306317 
    307318        $filelength = 0; 
     
    452463        if ($fsize <= 2*1024*1024*1024) { 
    453464            if (!$this->_fp = fopen($file, 'r')) { 
    454                 PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - Failed to open "' . $file . '"'); 
     465                $this->last_error = PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - Failed to open "' . $file . '"'); 
    455466                return false; 
    456467            } 
     
    458469        } else { 
    459470            if (PHP_OS != 'Linux') { 
    460                 PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - File size is greater than 2GB. This is only supported under Linux.'); 
     471                $this->last_error = PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - File size is greater than 2GB. This is only supported under Linux.'); 
    461472                return false; 
    462473            } 
  • trunk/example_mktorrent.php

    r26 r49  
    44 
    55require_once 'File/Bittorrent/MakeTorrent.php'; 
     6 
     7// Set error handling 
     8PEAR::setErrorHandling(PEAR_ERROR_PRINT); 
     9 
    610$MakeTorrent = new File_Bittorrent_MakeTorrent('example.php'); 
    711