Example #1
0
 /**
  * Intializing the object with its parsed value.
  *
  * Value is iterated and its values (and keys) are getting contained by the object.
  *
  * @param array $value
  */
 public function __construct(array $value = null)
 {
     $this->value = array();
     if (!isset($value)) {
         return;
     }
     if (PHPTracker_Bencode_Builder::isDictionary($value)) {
         foreach ($value as $key => $sub_value) {
             $this->contain($sub_value, new PHPTracker_Bencode_Value_String($key));
         }
     } else {
         foreach ($value as $sub_value) {
             $this->contain($sub_value);
         }
     }
 }
 /**
  * @expectedException PHPTracker_Bencode_Error_Build
  */
 public function testBuildErrorObject()
 {
     PHPTracker_Bencode_Builder::build((object) array('attribute' => 'something'));
 }
Example #3
0
 /**
  * Returns a bencoded string that represents a .torrent file and can be
  * read by Bittorrent clients.
  *
  * First item in the $announce_list will be used in the 'announce' key of
  * the .torrent file, which is compatible with the Bittorrent specification
  * ('announce-list' is an unofficial extension).
  *
  * @param array $announce_list List of URLs to make announcemenets to.
  * @return string
  */
 public function createTorrentFile(array $announce_list)
 {
     // Announce-list is a list of lists of strings.
     foreach ($announce_list as &$announce_item) {
         if (is_array($announce_item)) {
             continue;
         }
         $announce_item = array($announce_item);
     }
     $torrent_data = array('info' => array('piece length' => $this->size_piece, 'pieces' => $this->__get('pieces'), 'name' => $this->__get('name'), 'length' => $this->__get('length')), 'announce' => reset(reset($announce_list)), 'announce-list' => $announce_list);
     return PHPTracker_Bencode_Builder::build($torrent_data);
 }
Example #4
0
 /**
  * Creates a bencoded announce failure message.
  *
  * @param string $message Public description of the failure.
  * @return string
  */
 protected function announceFailure($message)
 {
     return PHPTracker_Bencode_Builder::build(array('failure reason' => $message));
 }