Torrent::__construct PHP Method

__construct() public method

Read and decode torrent file/data OR build a torrent from source folder/file(s) Supported signatures: - Torrent(); // get an instance (usefull to scrape and check errors) - Torrent( string $torrent ); // analyse a torrent file - Torrent( string $torrent, string $announce ); - Torrent( string $torrent, array $meta ); - Torrent( string $file_or_folder ); // create a torrent file - Torrent( string $file_or_folder, string $announce_url, [int $piece_length] ); - Torrent( string $file_or_folder, array $meta, [int $piece_length] ); - Torrent( array $files_list ); - Torrent( array $files_list, string $announce_url, [int $piece_length] ); - Torrent( array $files_list, array $meta, [int $piece_length] );
public __construct ( $data = null, $meta = [], $piece_length = 256 )
    public function __construct($data = null, $meta = array(), $piece_length = 256)
    {
        if (is_null($data)) {
            return false;
        }
        if ($piece_length < 32 || $piece_length > 4096) {
            return self::set_error(new Exception('Invalid piece lenth, must be between 32 and 4096'));
        }
        if (is_string($meta)) {
            $meta = array('announce' => $meta);
        }
        if ($this->build($data, $piece_length * 1024)) {
            $this->touch();
        } else {
            $meta = array_merge($meta, $this->decode($data));
        }
        foreach ($meta as $key => $value) {
            $this->{$key} = $value;
        }
    }

Usage Example

Ejemplo n.º 1
0
 public function __construct($data = null, $meta = array(), $piece_length = 256)
 {
     parent::__construct($data, $meta, $piece_length);
     $this->announce = "http://t411unlimited.tk/announce.php";
 }