/** * Factory method to use when creating a new torrent object * * @param string $type * @param array $params * @return Zend_BitTorrent_Torrent * @throws Zend_BitTorrent_Torrent_Exception */ public static function factory($type, $params = array()) { if ($params !== null && !is_array($params)) { /** @see Zend_BitTorrent_Torrent_Exception */ require_once 'Zend/BitTorrent/Torrent/Exception.php'; throw new Zend_BitTorrent_Torrent_Exception('$params must either be null or an array.'); } $torrent = new self(); if ($type === self::CREATE_FROM_FILE) { if (!isset($params['file'])) { /** @see Zend_BitTorrent_Torrent_Exception */ require_once 'Zend/BitTorrent/Torrent/Exception.php'; throw new Zend_BitTorrent_Torrent_Exception('Missing "file" parameter.'); } $torrent->setTorrentFilePath($params['file']); $torrent->buildFromTorrent(); } else { if ($type === self::CREATE_FROM_PATH) { if (!isset($params['path']) || !isset($params['announce'])) { /** @see Zend_BitTorrent_Torrent_Exception */ require_once 'Zend/BitTorrent/Torrent/Exception.php'; throw new Zend_BitTorrent_Torrent_Exception('Missing "path" and/or "announce" parameters.'); } $torrent->setPath($params['path'])->setAnnounce($params['announce'])->buildFromPath(); } else { if ($type === self::CREATE_NEW) { /* Do nothing */ } else { /** @see Zend_BitTorrent_Torrent_Exception */ require_once 'Zend/BitTorrent/Torrent/Exception.php'; throw new Zend_BitTorrent_Torrent_Exception('Invalid type.'); } } } return $torrent; }