Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

HTTP_Download -> HTTP_Download2

  • Loading branch information...
commit acdc114226cff9a5e80d2150a882e96640d7705a 1 parent 55c63fd
@CloCkWeRX CloCkWeRX authored
View
54 HTTP/Download.php
@@ -2,17 +2,17 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * HTTP::Download
+ * HTTP::Download2
*
* PHP versions 4 and 5
*
* @category HTTP
- * @package HTTP_Download
+ * @package HTTP_Download2
* @author Michael Wallner <mike@php.net>
* @copyright 2003-2005 Michael Wallner
* @license BSD, revised
* @version CVS: $Id$
- * @link http://pear.php.net/package/HTTP_Download
+ * @link http://pear.php.net/package/HTTP_Download2
*/
// {{{ includes
@@ -28,7 +28,7 @@
// }}}
// {{{ constants
-/**#@+ Use with HTTP_Download::setContentDisposition() **/
+/**#@+ Use with HTTP_Download2::setContentDisposition() **/
/**
* Send data as attachment
*/
@@ -88,13 +88,13 @@
* @access public
* @version $Revision$
*/
-class HTTP_Download
+class HTTP_Download2
{
// {{{ protected member variables
/**
* Path to file for download
*
- * @see HTTP_Download::setFile()
+ * @see HTTP_Download2::setFile()
* @access protected
* @var string
*/
@@ -103,7 +103,7 @@ class HTTP_Download
/**
* Data for download
*
- * @see HTTP_Download::setData()
+ * @see HTTP_Download2::setData()
* @access protected
* @var string
*/
@@ -112,7 +112,7 @@ class HTTP_Download
/**
* Resource handle for download
*
- * @see HTTP_Download::setResource()
+ * @see HTTP_Download2::setResource()
* @access protected
* @var int
*/
@@ -161,7 +161,7 @@ class HTTP_Download
'Pragma' => 'cache',
'Cache-Control' => 'public, must-revalidate, max-age=0',
'Accept-Ranges' => 'bytes',
- 'X-Sent-By' => 'PEAR::HTTP::Download'
+ 'X-Sent-By' => 'PEAR::HTTP::Download2'
);
/**
@@ -245,9 +245,9 @@ class HTTP_Download
* It looks like this:
* "Content-Disposition: attachment; filename=example.tgz".
*
- * @see HTTP_Download::setContentDisposition()
+ * @see HTTP_Download2::setContentDisposition()
*/
- function HTTP_Download($params = array())
+ function HTTP_Download2($params = array())
{
$this->HTTP = &new HTTP_Header;
$this->_error = $this->setParams($params);
@@ -264,7 +264,7 @@ function HTTP_Download($params = array())
* @return mixed Returns true on success or PEAR_Error on failure.
* @param array $params associative array of parameters
*
- * @see HTTP_Download::HTTP_Download()
+ * @see HTTP_Download2::HTTP_Download2()
*/
function setParams($params)
{
@@ -460,7 +460,7 @@ function setCacheControl($cache = 'public', $maxage = 0)
* Set ETag
*
* Sets a user-defined ETag for cache-validation. The ETag is usually
- * generated by HTTP_Download through its payload information.
+ * generated by HTTP_Download2 through its payload information.
*
* @access public
* @return void
@@ -508,7 +508,7 @@ function setBufferSize($bytes = 2097152)
* Set the amount of seconds to sleep after each chunck that has been
* sent. One can implement some sort of throttle through adjusting the
* buffer size and the throttle delay. With the following settings
- * HTTP_Download will sleep a second after each 25 K of data sent.
+ * HTTP_Download2 will sleep a second after each 25 K of data sent.
*
* <code>
* Array(
@@ -534,8 +534,8 @@ function setThrottleDelay($seconds = 0)
/**
* Set "Last-Modified"
*
- * This is usually determined by filemtime() in HTTP_Download::setFile()
- * If you set raw data for download with HTTP_Download::setData() and you
+ * This is usually determined by filemtime() in HTTP_Download2::setFile()
+ * If you set raw data for download with HTTP_Download2::setData() and you
* want do send an appropiate "Last-Modified" header, you should call this
* method.
*
@@ -551,7 +551,7 @@ function setLastModified($last_modified)
/**
* Set Content-Disposition header
*
- * @see HTTP_Download::HTTP_Download
+ * @see HTTP_Download2::HTTP_Download2
*
* @access public
* @return void
@@ -562,7 +562,7 @@ function setLastModified($last_modified)
*
* <b>Example:</b>
* <code>
- * $HTTP_Download->setContentDisposition(
+ * $HTTP_Download2->setContentDisposition(
* HTTP_DOWNLOAD_ATTACHMENT,
* 'download.tgz'
* );
@@ -751,19 +751,19 @@ function send($autoSetContentDisposition = true)
/**
* Static send
*
- * @see HTTP_Download::HTTP_Download()
- * @see HTTP_Download::send()
+ * @see HTTP_Download2::HTTP_Download2()
+ * @see HTTP_Download2::send()
*
* @static
* @access public
* @return mixed Returns true on success or PEAR_Error on failure.
* @param array $params associative array of parameters
- * @param bool $guess whether HTTP_Download::guessContentType()
+ * @param bool $guess whether HTTP_Download2::guessContentType()
* should be called
*/
function staticSend($params, $guess = false)
{
- $d = &new HTTP_Download();
+ $d = &new HTTP_Download2();
$e = $d->setParams($params);
if (PEAR::isError($e)) {
return $e;
@@ -782,8 +782,8 @@ function staticSend($params, $guess = false)
*
* Example:
* <code>
- * require_once 'HTTP/Download.php';
- * HTTP_Download::sendArchive(
+ * require_once 'HTTP/Download2.php';
+ * HTTP_Download2::sendArchive(
* 'myArchive.tgz',
* '/var/ftp/pub/mike',
* HTTP_DOWNLOAD_TGZ,
@@ -793,7 +793,7 @@ function staticSend($params, $guess = false)
* </code>
*
* @see Archive_Tar::createModify()
- * @deprecated use HTTP_Download_Archive::send()
+ * @deprecated use HTTP_Download2_Archive::send()
* @static
* @access public
* @return mixed Returns true on success or PEAR_Error on failure.
@@ -809,8 +809,8 @@ function sendArchive( $name,
$add_path = '',
$strip_path = '')
{
- require_once 'HTTP/Download/Archive.php';
- return HTTP_Download_Archive::send($name, $files, $type,
+ require_once 'HTTP/Download2/Archive.php';
+ return HTTP_Download2_Archive::send($name, $files, $type,
$add_path, $strip_path);
}
// }}}
View
38 HTTP/Download/Archive.php
@@ -2,46 +2,46 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * HTTP::Download::Archive
- *
+ * HTTP::Download2::Archive
+ *
* PHP versions 4 and 5
*
* @category HTTP
- * @package HTTP_Download
+ * @package HTTP_Download2
* @author Michael Wallner <mike@php.net>
* @copyright 2003-2005 Michael Wallner
* @license BSD, revisewd
* @version CVS: $Id$
- * @link http://pear.php.net/package/HTTP_Download
+ * @link http://pear.php.net/package/HTTP_Download2
*/
/**
- * Requires HTTP_Download
+ * Requires HTTP_Download2
*/
-require_once 'HTTP/Download.php';
+require_once 'HTTP/Download2.php';
/**
* Requires System
*/
require_once 'System.php';
-/**
- * HTTP_Download_Archive
- *
+/**
+ * HTTP_Download2_Archive
+ *
* Helper class for sending Archives.
*
* @access public
* @version $Revision$
*/
-class HTTP_Download_Archive
+class HTTP_Download2_Archive
{
/**
* Send a bunch of files or directories as an archive
- *
+ *
* Example:
* <code>
- * require_once 'HTTP/Download/Archive.php';
- * HTTP_Download_Archive::send(
+ * require_once 'HTTP/Download2/Archive.php';
+ * HTTP_Download2_Archive::send(
* 'myArchive.tgz',
* '/var/ftp/pub/mike',
* HTTP_DOWNLOAD_BZ2,
@@ -63,7 +63,7 @@ class HTTP_Download_Archive
function send($name, $files, $type = HTTP_DOWNLOAD_TGZ, $add_path = '', $strip_path = '')
{
$tmp = System::mktemp();
-
+
switch ($type = strToUpper($type))
{
case HTTP_DOWNLOAD_TAR:
@@ -89,16 +89,16 @@ function send($name, $files, $type = HTTP_DOWNLOAD_TGZ, $add_path = '', $strip_p
$arc = &new Archive_Zip($tmp);
$content_type = 'x-zip';
break;
-
+
default:
return PEAR::raiseError(
'Archive type not supported: ' . $type,
HTTP_DOWNLOAD_E_INVALID_ARCHIVE_TYPE
);
}
-
+
if ($type == HTTP_DOWNLOAD_ZIP) {
- $options = array( 'add_path' => $add_path,
+ $options = array( 'add_path' => $add_path,
'remove_path' => $strip_path);
if (!$arc->create($files, $options)) {
return PEAR::raiseError('Archive creation failed.');
@@ -112,8 +112,8 @@ function send($name, $files, $type = HTTP_DOWNLOAD_TGZ, $add_path = '', $strip_p
}
}
unset($arc);
-
- $dl = &new HTTP_Download(array('file' => $tmp));
+
+ $dl = &new HTTP_Download2(array('file' => $tmp));
$dl->setContentType('application/' . $content_type);
$dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $name);
return $dl->send();
View
78 HTTP/Download/PgLOB.php
@@ -2,45 +2,45 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
- * HTTP::Download::PgLOB
- *
+ * HTTP::Download2::PgLOB
+ *
* PHP versions 4 and 5
*
* @category HTTP
- * @package HTTP_Download
+ * @package HTTP_Download2
* @author Michael Wallner <mike@php.net>
* @copyright 2003-2005 Michael Wallner
* @license BSD, revised
* @version CVS: $Id$
- * @link http://pear.php.net/package/HTTP_Download
+ * @link http://pear.php.net/package/HTTP_Download2
*/
-$GLOBALS['_HTTP_Download_PgLOB_Connection'] = null;
-stream_register_wrapper('pglob', 'HTTP_Download_PgLOB');
+$GLOBALS['_HTTP_Download2_PgLOB_Connection'] = null;
+stream_register_wrapper('pglob', 'HTTP_Download2_PgLOB');
/**
- * PgSQL large object stream interface for HTTP_Download
- *
+ * PgSQL large object stream interface for HTTP_Download2
+ *
* Usage:
* <code>
- * require_once 'HTTP/Download.php';
- * require_once 'HTTP/Download/PgLOB.php';
+ * require_once 'HTTP/Download2.php';
+ * require_once 'HTTP/Download2/PgLOB.php';
* $db = &DB::connect('pgsql://user:pass@host/db');
* // or $db = pg_connect(...);
- * $lo = HTTP_Download_PgLOB::open($db, 12345);
- * $dl = &new HTTP_Download;
+ * $lo = HTTP_Download2_PgLOB::open($db, 12345);
+ * $dl = &new HTTP_Download2;
* $dl->setResource($lo);
* $dl->send()
* </code>
- *
+ *
* @access public
* @version $Revision$
*/
-class HTTP_Download_PgLOB
+class HTTP_Download2_PgLOB
{
/**
* Set Connection
- *
+ *
* @static
* @access public
* @return bool
@@ -50,34 +50,34 @@ function setConnection($conn)
{
if (is_a($conn, 'DB_Common')) {
$conn = $conn->dbh;
- } elseif ( is_a($conn, 'MDB_Common') ||
+ } elseif ( is_a($conn, 'MDB_Common') ||
is_a($conn, 'MDB2_Driver_Common')) {
$conn = $conn->connection;
}
if ($isResource = is_resource($conn)) {
- $GLOBALS['_HTTP_Download_PgLOB_Connection'] = $conn;
+ $GLOBALS['_HTTP_Download2_PgLOB_Connection'] = $conn;
}
return $isResource;
}
-
+
/**
* Get Connection
- *
+ *
* @static
* @access public
* @return resource
*/
function getConnection()
{
- if (is_resource($GLOBALS['_HTTP_Download_PgLOB_Connection'])) {
- return $GLOBALS['_HTTP_Download_PgLOB_Connection'];
+ if (is_resource($GLOBALS['_HTTP_Download2_PgLOB_Connection'])) {
+ return $GLOBALS['_HTTP_Download2_PgLOB_Connection'];
}
return null;
}
-
+
/**
* Open
- *
+ *
* @static
* @access public
* @return resource
@@ -87,10 +87,10 @@ function getConnection()
*/
function open($conn, $loid, $mode = 'rb')
{
- HTTP_Download_PgLOB::setConnection($conn);
+ HTTP_Download2_PgLOB::setConnection($conn);
return fopen('pglob:///'. $loid, $mode);
}
-
+
/**#@+
* Stream Interface Implementation
* @internal
@@ -99,69 +99,69 @@ function open($conn, $loid, $mode = 'rb')
var $size = 0;
var $conn = null;
var $handle = null;
-
+
function stream_open($path, $mode)
{
- if (!$this->conn = HTTP_Download_PgLOB::getConnection()) {
+ if (!$this->conn = HTTP_Download2_PgLOB::getConnection()) {
return false;
}
if (!preg_match('/(\d+)/', $path, $matches)) {
return false;
}
$this->ID = $matches[1];
-
+
if (!pg_query($this->conn, 'BEGIN')) {
return false;
}
-
+
$this->handle = pg_lo_open($this->conn, $this->ID, $mode);
if (!is_resource($this->handle)) {
return false;
}
-
+
// fetch size of lob
pg_lo_seek($this->handle, 0, PGSQL_SEEK_END);
$this->size = (int) pg_lo_tell($this->handle);
pg_lo_seek($this->handle, 0, PGSQL_SEEK_SET);
-
+
return true;
}
-
+
function stream_read($length)
{
return pg_lo_read($this->handle, $length);
}
-
+
function stream_seek($offset, $whence = SEEK_SET)
{
return pg_lo_seek($this->handle, $offset, $whence);
}
-
+
function stream_tell()
{
return pg_lo_tell($this->handle);
}
-
+
function stream_eof()
{
return pg_lo_tell($this->handle) >= $this->size;
}
-
+
function stream_flush()
{
return true;
}
-
+
function stream_stat()
{
return array('size' => $this->size, 'ino' => $this->ID);
}
-
+
function stream_write($data)
{
return pg_lo_write($this->handle, $data);
}
-
+
function stream_close()
{
if (pg_lo_close($this->handle)) {
View
12 tests/AllTests.php
@@ -6,15 +6,15 @@
// Called via php, not PHPUnit. Pass the request to PHPUnit.
if (!defined('PHPUnit_MAIN_METHOD')) {
/** The test's main method name */
- define('PHPUnit_MAIN_METHOD', 'HTML_Download_AllTests::main');
+ define('PHPUnit_MAIN_METHOD', 'HTML_Download2_AllTests::main');
$call_main = true;
}
}
require_once dirname(__FILE__) . '/helper.inc';
-require_once dirname(__FILE__) . '/HTTP_DownloadTest.php';
+require_once dirname(__FILE__) . '/HTTP_Download2Test.php';
-class HTML_Download_AllTests
+class HTML_Download2_AllTests
{
public static function main()
{
@@ -23,14 +23,14 @@ public static function main()
public static function suite()
{
- $suite = new PHPUnit_Framework_TestSuite('PEAR - HTML_Download');
+ $suite = new PHPUnit_Framework_TestSuite('PEAR - HTML_Download2');
- $suite->addTestSuite('HTTP_DownloadTest');
+ $suite->addTestSuite('HTTP_Download2Test');
return $suite;
}
}
if ($call_main) {
- HTML_Download_AllTests::main();
+ HTML_Download2_AllTests::main();
}
View
24 tests/HTTP_DownloadTest.php
@@ -2,30 +2,30 @@
require_once dirname(__FILE__) . '/helper.inc';
-require_once 'HTTP/Download.php';
+require_once 'HTTP/Download2.php';
require_once 'HTTP/Request.php';
-class HTTP_DownloadTest extends PHPUnit_Framework_TestCase {
+class HTTP_Download2Test extends PHPUnit_Framework_TestCase {
function setUp()
{
- $this->testScript = 'http://local/www/mike/pear/HTTP_Download/tests/send.php';
+ $this->testScript = 'http://local/www/mike/pear/HTTP_Download2/tests/send.php';
}
function tearDown()
{
}
- function testHTTP_Download()
+ function testHTTP_Download2()
{
- $this->assertTrue(is_a($h = &new HTTP_Download, 'HTTP_Download'));
+ $this->assertTrue(is_a($h = &new HTTP_Download2, 'HTTP_Download2'));
$this->assertTrue(is_a($h->HTTP, 'HTTP_Header'));
unset($h);
}
function testsetFile()
{
- $h = &new HTTP_Download;
+ $h = &new HTTP_Download2;
$this->assertFalse(PEAR::isError($h->setFile(dirname(__FILE__) . '/data.txt')), '$h->setFile("data.txt")');
$this->assertEquals(realpath(dirname(__FILE__) . '/data.txt'), $h->file, '$h->file == "data.txt');
$this->assertTrue(PEAR::isError($h->setFile('nonexistant', false)), '$h->setFile("nonexistant")');
@@ -34,7 +34,7 @@ function testsetFile()
function testsetData()
{
- $h = &new HTTP_Download;
+ $h = &new HTTP_Download2;
$this->assertTrue(null === $h->setData('foo'), 'null === $h->setData("foo")');
$this->assertEquals('foo', $h->data, '$h->data == "foo"');
unset($h);
@@ -42,7 +42,7 @@ function testsetData()
function testsetResource()
{
- $h = &new HTTP_Download;
+ $h = &new HTTP_Download2;
$this->assertFalse(PEAR::isError($h->setResource($f = fopen(dirname(__FILE__) . '/data.txt', 'r'))), '$h->setResource(fopen("data.txt","r"))');
$this->assertEquals($f, $h->handle, '$h->handle == $f');
fclose($f); $f = -1;
@@ -52,7 +52,7 @@ function testsetResource()
function testsetGzip()
{
- $h = &new HTTP_Download;
+ $h = &new HTTP_Download2;
$this->assertFalse(PEAR::isError($h->setGzip(false)), '$h->setGzip(false)');
$this->assertFalse($h->gzip, '$h->gzip');
if (PEAR::loadExtension('zlib')) {
@@ -67,7 +67,7 @@ function testsetGzip()
function testsetContentType()
{
- $h = &new HTTP_Download;
+ $h = &new HTTP_Download2;
$this->assertFalse(PEAR::isError($h->setContentType('text/html;charset=iso-8859-1')), '$h->setContentType("text/html;charset=iso-8859-1")');
$this->assertTrue(PEAR::isError($h->setContentType('##++***!§§§§?°°^^}][{')), '$h->setContentType("some weird characters")');
$this->assertEquals('text/html;charset=iso-8859-1', $h->headers['Content-Type'], '$h->headers["Content-Type"] == "text/html;charset=iso-8859-1"');
@@ -76,7 +76,7 @@ function testsetContentType()
function testguessContentType()
{
- $h = &new HTTP_Download(array('file' => dirname(__FILE__) . '/data.txt'));
+ $h = &new HTTP_Download2(array('file' => dirname(__FILE__) . '/data.txt'));
$e = $h->guessContentType();
if (PEAR::isError($e) && $e->getCode() != HTTP_DOWNLOAD_E_NO_EXT_MMAGIC) {
$this->assertTrue(false, $e->getMessage());
@@ -90,7 +90,7 @@ function _send($op)
$this->markTestSkipped($this->testScript . " is not available");
}
$complete = str_repeat('1234567890',10);
-
+
$r = &new HTTP_Request($this->testScript);
foreach (array('file', 'resource', 'data') as $what) {
$r->reset($this->testScript);
View
8 tests/send.php
@@ -1,7 +1,7 @@
<?php
require_once 'PEAR.php';
-require_once 'HTTP/Download.php';
+require_once 'HTTP/Download2.php';
PEAR::setErrorHandling(PEAR_ERROR_PRINT);
@@ -73,17 +73,17 @@ function stream_stat()
switch ($_GET['op'])
{
case 'static':
- HTTP_Download::staticSend($params);
+ HTTP_Download2::staticSend($params);
break;
case 'send':
- $h = &new HTTP_Download;
+ $h = &new HTTP_Download2;
$h->setParams($params);
$h->send();
break;
case 'arch':
- HTTP_Download::sendArchive('foo.'. $_GET['type'], $_GET['what'], $_GET['type']);
+ HTTP_Download2::sendArchive('foo.'. $_GET['type'], $_GET['what'], $_GET['type']);
break;
}
Please sign in to comment.
Something went wrong with that request. Please try again.