Example #1
0
 /**
  * Populate the instance of the object based on a torrent file
  *
  * @param string $path Path to the torrent file
  * @param DecoderInterface $decoder The decoder to use to decode the file
  * @throws InvalidArgumentException
  * @return Torrent Returns a new instance of this class
  */
 public static function createFromTorrentFile($path, DecoderInterface $decoder = null)
 {
     if (!is_file($path)) {
         throw new InvalidArgumentException($path . ' does not exist.');
     }
     // Make sure we have a decoder
     if ($decoder === null) {
         $decoder = new Decoder();
     }
     $decodedFile = $decoder->decodeFile($path);
     // Create a new torrent
     $torrent = new static();
     // Populate the object with data from the file
     if (isset($decodedFile['announce'])) {
         $torrent->setAnnounce($decodedFile['announce']);
         unset($decodedFile['announce']);
     }
     if (isset($decodedFile['announce-list'])) {
         $torrent->setAnnounceList($decodedFile['announce-list']);
         unset($decodedFile['announce-list']);
     }
     if (isset($decodedFile['comment'])) {
         $torrent->setComment($decodedFile['comment']);
         unset($decodedFile['comment']);
     }
     if (isset($decodedFile['created by'])) {
         $torrent->setCreatedBy($decodedFile['created by']);
         unset($decodedFile['created by']);
     }
     if (isset($decodedFile['creation date'])) {
         $torrent->setCreatedAt($decodedFile['creation date']);
         unset($decodedFile['creation date']);
     }
     if (isset($decodedFile['info'])) {
         $torrent->setInfo($decodedFile['info']);
         unset($decodedFile['info']);
     }
     // add any extra meta info fields that were left in this file
     if (count($decodedFile) > 0) {
         $torrent->setExtraMeta($decodedFile);
     }
     return $torrent;
 }
Example #2
0
 function setResponse($string)
 {
     $decoder = new Decoder();
     $this->response = $decoder->decode($string);
 }