J7mbo / TorrentPHP

Provides a simple-to-use object oriented interface for interacting with torrent clients.
Other
41 stars 16 forks source link

getTorrents(): array error adding torrent using example #1

Closed mozzwald closed 9 years ago

mozzwald commented 9 years ago

Using the following code (pulled from your example) I get errors when I add a new torrent. What is the correct format for the $id array passed to getTorrents()?

error_reporting(E_ALL);
ini_set("display_errors", 1);

require_once __DIR__ . "/vendor/autoload.php";

use TorrentPHP\Client\Deluge\ConnectionConfig,
    TorrentPHP\Client\Deluge\ClientTransport,
    TorrentPHP\Client\Deluge\ClientAdapter,
    TorrentPHP\TorrentFactory,
    TorrentPHP\FileFactory;

// Create the HTTP Client Object
$client = new Artax\Client;

// Create the HTTP Client Request
$request = new Artax\Request;

// Configuration
$config = new ConnectionConfig(array(
    'host'     => '127.0.0.1',
    'port'     => 8112,
    'password' => '************'
));

// Create the transport that returns json
$transport = new ClientTransport($client, $request, $config);
echo "Transport Created<br>";

// Create the adapter that returns Torrent objects
$adapter = new ClientAdapter($transport, new TorrentFactory, new FileFactory);
echo "Adapter Created<br>";

// Add a torrent, and get back a Torrent object
$torrent = $adapter->addTorrent('http://releases.ubuntu.com/14.04/ubuntu-14.04-server-i386.iso.torrent');
Catchable fatal error: Argument 1 passed to TorrentPHP\Client\Deluge\ClientAdapter::getTorrents() must be of the type array, string given, called in torrentphp/src/Client/Deluge/ClientAdapter.php on line 68 and defined in torrentphp/src/Client/Deluge/ClientAdapter.php on line 18
``
J7mbo commented 9 years ago

getTorrents() now requires an array of id's, so you can get multiple torrents if you wish. Here's the method signature:

public function getTorrents(array $ids = array())

Try put your id in an array and pass that through?

If you want to check the source for that, you can see it here.

Of course, you can pass no ids through and get all of them as usual.

mozzwald commented 9 years ago

Thanks for the pointer. I forked and made some changes that got it working:

https://github.com/mozzwald/TorrentPHP/commit/ef6205b4e2869919040c15513d8f748d6bad53b2