Skip to content

Commit

Permalink
HTTP_Download -> HTTP_Download2
Browse files Browse the repository at this point in the history
  • Loading branch information
CloCkWeRX committed Jan 10, 2012
1 parent 55d0331 commit 282645a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 52 deletions.
84 changes: 42 additions & 42 deletions HTTP/Download2.php
Expand Up @@ -32,44 +32,44 @@
/**
* Send data as attachment
*/
define('HTTP_DOWNLOAD_ATTACHMENT', 'attachment');
define('HTTP_DOWNLOAD2_ATTACHMENT', 'attachment');
/**
* Send data inline
*/
define('HTTP_DOWNLOAD_INLINE', 'inline');
define('HTTP_DOWNLOAD2_INLINE', 'inline');
/**#@-**/

/**#@+ Use with HTTP_Download::sendArchive() **/
/**
* Send as uncompressed tar archive
*/
define('HTTP_DOWNLOAD_TAR', 'TAR');
define('HTTP_DOWNLOAD2_TAR', 'TAR');
/**
* Send as gzipped tar archive
*/
define('HTTP_DOWNLOAD_TGZ', 'TGZ');
define('HTTP_DOWNLOAD2_TGZ', 'TGZ');
/**
* Send as bzip2 compressed tar archive
*/
define('HTTP_DOWNLOAD_BZ2', 'BZ2');
define('HTTP_DOWNLOAD2_BZ2', 'BZ2');
/**
* Send as zip archive
*/
define('HTTP_DOWNLOAD_ZIP', 'ZIP');
define('HTTP_DOWNLOAD2_ZIP', 'ZIP');
/**#@-**/

/**#@+
* Error constants
*/
define('HTTP_DOWNLOAD_E_HEADERS_SENT', -1);
define('HTTP_DOWNLOAD_E_NO_EXT_ZLIB', -2);
define('HTTP_DOWNLOAD_E_NO_EXT_MMAGIC', -3);
define('HTTP_DOWNLOAD_E_INVALID_FILE', -4);
define('HTTP_DOWNLOAD_E_INVALID_PARAM', -5);
define('HTTP_DOWNLOAD_E_INVALID_RESOURCE', -6);
define('HTTP_DOWNLOAD_E_INVALID_REQUEST', -7);
define('HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE', -8);
define('HTTP_DOWNLOAD_E_INVALID_ARCHIVE_TYPE', -9);
define('HTTP_DOWNLOAD2_E_HEADERS_SENT', -1);
define('HTTP_DOWNLOAD2_E_NO_EXT_ZLIB', -2);
define('HTTP_DOWNLOAD2_E_NO_EXT_MMAGIC', -3);
define('HTTP_DOWNLOAD2_E_INVALID_FILE', -4);
define('HTTP_DOWNLOAD2_E_INVALID_PARAM', -5);
define('HTTP_DOWNLOAD2_E_INVALID_RESOURCE', -6);
define('HTTP_DOWNLOAD2_E_INVALID_REQUEST', -7);
define('HTTP_DOWNLOAD2_E_INVALID_CONTENT_TYPE', -8);
define('HTTP_DOWNLOAD2_E_INVALID_ARCHIVE_TYPE', -9);
/**#@-**/
// }}}

Expand Down Expand Up @@ -278,7 +278,7 @@ function setParams($params)
if (!method_exists($this, $method)) {
return PEAR::raiseError(
"Method '$method' doesn't exist.",
HTTP_DOWNLOAD_E_INVALID_PARAM
HTTP_DOWNLOAD2_E_INVALID_PARAM
);
}

Expand All @@ -295,7 +295,7 @@ function setParams($params)
* Set path to file for download
*
* The Last-Modified header will be set to files filemtime(), actually.
* Returns PEAR_Error (HTTP_DOWNLOAD_E_INVALID_FILE) if file doesn't exist.
* Returns PEAR_Error (HTTP_DOWNLOAD2_E_INVALID_FILE) if file doesn't exist.
* Sends HTTP 404 or 403 status if $send_error is set to true.
*
* @access public
Expand All @@ -317,7 +317,7 @@ function setFile($file, $send_error = true)
}
return PEAR::raiseError(
"File '$file' not found.",
HTTP_DOWNLOAD_E_INVALID_FILE
HTTP_DOWNLOAD2_E_INVALID_FILE
);
}
if (!is_readable($file)) {
Expand All @@ -326,7 +326,7 @@ function setFile($file, $send_error = true)
}
return PEAR::raiseError(
"Cannot read file '$file'.",
HTTP_DOWNLOAD_E_INVALID_FILE
HTTP_DOWNLOAD2_E_INVALID_FILE
);
}
$this->setLastModified(filemtime($file));
Expand Down Expand Up @@ -354,7 +354,7 @@ function setData($data = null)
* Set resource for download
*
* The resource handle supplied will be closed after sending the download.
* Returns a PEAR_Error (HTTP_DOWNLOAD_E_INVALID_RESOURCE) if $handle
* Returns a PEAR_Error (HTTP_DOWNLOAD2_E_INVALID_RESOURCE) if $handle
* is no valid resource. Set $handle to null if you want to unset this.
*
* @access public
Expand Down Expand Up @@ -383,14 +383,14 @@ function setResource($handle = null)

return PEAR::raiseError(
"Handle '$handle' is no valid resource.",
HTTP_DOWNLOAD_E_INVALID_RESOURCE
HTTP_DOWNLOAD2_E_INVALID_RESOURCE
);
}

/**
* Whether to gzip the download
*
* Returns a PEAR_Error (HTTP_DOWNLOAD_E_NO_EXT_ZLIB)
* Returns a PEAR_Error (HTTP_DOWNLOAD2_E_NO_EXT_ZLIB)
* if ext/zlib is not available/loadable.
*
* @access public
Expand All @@ -406,7 +406,7 @@ function setGzip($gzip = false)
if ($gzip && !PEAR::loadExtension('zlib')){
return PEAR::raiseError(
'GZIP compression (ext/zlib) not available.',
HTTP_DOWNLOAD_E_NO_EXT_ZLIB
HTTP_DOWNLOAD2_E_NO_EXT_ZLIB
);
}
$this->gzip = (bool) $gzip;
Expand Down Expand Up @@ -480,7 +480,7 @@ function setETag($etag = null)
* you set a very low buffer size that the actual file size may grow
* due to added gzip headers for each sent chunk of the specified size.
*
* Returns PEAR_Error (HTTP_DOWNLOAD_E_INVALID_PARAM) if $size is not
* Returns PEAR_Error (HTTP_DOWNLOAD2_E_INVALID_PARAM) if $size is not
* greater than 0 bytes.
*
* @access public
Expand All @@ -496,7 +496,7 @@ function setBufferSize($bytes = 2097152)
if (0 >= $bytes) {
return PEAR::raiseError(
'Buffer size must be greater than 0 bytes ('. $bytes .' given)',
HTTP_DOWNLOAD_E_INVALID_PARAM);
HTTP_DOWNLOAD2_E_INVALID_PARAM);
}
$this->bufferSize = abs($bytes);
return true;
Expand Down Expand Up @@ -563,12 +563,12 @@ function setLastModified($last_modified)
* <b>Example:</b>
* <code>
* $HTTP_Download2->setContentDisposition(
* HTTP_DOWNLOAD_ATTACHMENT,
* HTTP_DOWNLOAD2_ATTACHMENT,
* 'download.tgz'
* );
* </code>
*/
function setContentDisposition( $disposition = HTTP_DOWNLOAD_ATTACHMENT,
function setContentDisposition( $disposition = HTTP_DOWNLOAD2_ATTACHMENT,
$file_name = null)
{
$cd = $disposition;
Expand All @@ -584,7 +584,7 @@ function setContentDisposition( $disposition = HTTP_DOWNLOAD_ATTACHMENT,
* Set content type of the download
*
* Default content type of the download will be 'application/x-octetstream'.
* Returns PEAR_Error (HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE) if
* Returns PEAR_Error (HTTP_DOWNLOAD2_E_INVALID_CONTENT_TYPE) if
* $content_type doesn't seem to be valid.
*
* @access public
Expand All @@ -600,7 +600,7 @@ function setContentType($content_type = 'application/x-octetstream')
if (!preg_match('/^[a-z]+\w*\/[a-z]+[\w.;= -]*$/', $content_type)) {
return PEAR::raiseError(
"Invalid content type '$content_type' supplied.",
HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE
HTTP_DOWNLOAD2_E_INVALID_CONTENT_TYPE
);
}
$this->headers['Content-Type'] = $content_type;
Expand All @@ -615,12 +615,12 @@ function setContentType($content_type = 'application/x-octetstream')
*
* Returns PEAR_Error if:
* o if PEAR::MIME_Type failed to detect a proper content type
* (HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE)
* (HTTP_DOWNLOAD2_E_INVALID_CONTENT_TYPE)
* o ext/magic.mime is not installed, or not properly configured
* (HTTP_DOWNLOAD_E_NO_EXT_MMAGIC)
* (HTTP_DOWNLOAD2_E_NO_EXT_MMAGIC)
* o mime_content_type() couldn't guess content type or returned
* a content type considered to be bogus by setContentType()
* (HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE)
* (HTTP_DOWNLOAD2_E_INVALID_CONTENT_TYPE)
*
* @access public
* @return mixed Returns true on success or PEAR_Error on failure.
Expand All @@ -634,26 +634,26 @@ function guessContentType()
if (class_exists('MIME_Type') || @include_once 'MIME/Type.php') {
if (PEAR::isError($mime_type = MIME_Type::autoDetect($this->file))) {
return PEAR::raiseError($mime_type->getMessage(),
HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE);
HTTP_DOWNLOAD2_E_INVALID_CONTENT_TYPE);
}
return $this->setContentType($mime_type);
}
if (!function_exists('mime_content_type')) {
return PEAR::raiseError(
'This feature requires ext/mime_magic!',
HTTP_DOWNLOAD_E_NO_EXT_MMAGIC
HTTP_DOWNLOAD2_E_NO_EXT_MMAGIC
);
}
if (!is_file(ini_get('mime_magic.magicfile'))) {
return PEAR::raiseError(
'ext/mime_magic is loaded but not properly configured!',
HTTP_DOWNLOAD_E_NO_EXT_MMAGIC
HTTP_DOWNLOAD2_E_NO_EXT_MMAGIC
);
}
if (!$content_type = @mime_content_type($this->file)) {
return PEAR::raiseError(
'Couldn\'t guess content type with mime_content_type().',
HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE
HTTP_DOWNLOAD2_E_INVALID_CONTENT_TYPE
);
}
return $this->setContentType($content_type);
Expand All @@ -663,8 +663,8 @@ function guessContentType()
* Send
*
* Returns PEAR_Error if:
* o HTTP headers were already sent (HTTP_DOWNLOAD_E_HEADERS_SENT)
* o HTTP Range was invalid (HTTP_DOWNLOAD_E_INVALID_REQUEST)
* o HTTP headers were already sent (HTTP_DOWNLOAD2_E_HEADERS_SENT)
* o HTTP Range was invalid (HTTP_DOWNLOAD2_E_INVALID_REQUEST)
*
* @access public
* @return mixed Returns true on success or PEAR_Error on failure.
Expand All @@ -680,7 +680,7 @@ function send($autoSetContentDisposition = true)
if (headers_sent()) {
return PEAR::raiseError(
'Headers already sent.',
HTTP_DOWNLOAD_E_HEADERS_SENT
HTTP_DOWNLOAD2_E_HEADERS_SENT
);
}

Expand Down Expand Up @@ -786,7 +786,7 @@ function staticSend($params, $guess = false)
* HTTP_Download2::sendArchive(
* 'myArchive.tgz',
* '/var/ftp/pub/mike',
* HTTP_DOWNLOAD_TGZ,
* HTTP_DOWNLOAD2_TGZ,
* '',
* '/var/ftp/pub'
* );
Expand All @@ -805,7 +805,7 @@ function staticSend($params, $guess = false)
*/
function sendArchive( $name,
$files,
$type = HTTP_DOWNLOAD_TGZ,
$type = HTTP_DOWNLOAD2_TGZ,
$add_path = '',
$strip_path = '')
{
Expand Down Expand Up @@ -1002,7 +1002,7 @@ function getChunks()
// response with a status of 416 (Requested range not satisfiable).
if (!$satisfiable) {
$error = PEAR::raiseError('Error processing range request',
HTTP_DOWNLOAD_E_INVALID_REQUEST);
HTTP_DOWNLOAD2_E_INVALID_REQUEST);
return $error;
}
//$this->sortChunks($parts);
Expand Down
18 changes: 9 additions & 9 deletions HTTP/Download2/Archive.php
Expand Up @@ -44,7 +44,7 @@ class HTTP_Download2_Archive
* HTTP_Download2_Archive::send(
* 'myArchive.tgz',
* '/var/ftp/pub/mike',
* HTTP_DOWNLOAD_BZ2,
* HTTP_DOWNLOAD2_BZ2,
* '',
* '/var/ftp/pub'
* );
Expand All @@ -60,31 +60,31 @@ class HTTP_Download2_Archive
* @param string $add_path path that should be prepended to the files
* @param string $strip_path path that should be stripped from the files
*/
function send($name, $files, $type = HTTP_DOWNLOAD_TGZ, $add_path = '', $strip_path = '')
function send($name, $files, $type = HTTP_DOWNLOAD2_TGZ, $add_path = '', $strip_path = '')
{
$tmp = System::mktemp();

switch ($type = strToUpper($type))
{
case HTTP_DOWNLOAD_TAR:
case HTTP_DOWNLOAD2_TAR:
include_once 'Archive/Tar.php';
$arc = &new Archive_Tar($tmp);
$content_type = 'x-tar';
break;

case HTTP_DOWNLOAD_TGZ:
case HTTP_DOWNLOAD2_TGZ:
include_once 'Archive/Tar.php';
$arc = &new Archive_Tar($tmp, 'gz');
$content_type = 'x-gzip';
break;

case HTTP_DOWNLOAD_BZ2:
case HTTP_DOWNLOAD2_BZ2:
include_once 'Archive/Tar.php';
$arc = &new Archive_Tar($tmp, 'bz2');
$content_type = 'x-bzip2';
break;

case HTTP_DOWNLOAD_ZIP:
case HTTP_DOWNLOAD2_ZIP:
include_once 'Archive/Zip.php';
$arc = &new Archive_Zip($tmp);
$content_type = 'x-zip';
Expand All @@ -93,11 +93,11 @@ function send($name, $files, $type = HTTP_DOWNLOAD_TGZ, $add_path = '', $strip_p
default:
return PEAR::raiseError(
'Archive type not supported: ' . $type,
HTTP_DOWNLOAD_E_INVALID_ARCHIVE_TYPE
HTTP_DOWNLOAD2_E_INVALID_ARCHIVE_TYPE
);
}

if ($type == HTTP_DOWNLOAD_ZIP) {
if ($type == HTTP_DOWNLOAD2_ZIP) {
$options = array( 'add_path' => $add_path,
'remove_path' => $strip_path);
if (!$arc->create($files, $options)) {
Expand All @@ -115,7 +115,7 @@ function send($name, $files, $type = HTTP_DOWNLOAD_TGZ, $add_path = '', $strip_p

$dl = &new HTTP_Download2(array('file' => $tmp));
$dl->setContentType('application/' . $content_type);
$dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $name);
$dl->setContentDisposition(HTTP_DOWNLOAD2_ATTACHMENT, $name);
return $dl->send();
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/HTTP_Download2Test.php
Expand Up @@ -78,7 +78,7 @@ function testguessContentType()
{
$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) {
if (PEAR::isError($e) && $e->getCode() != HTTP_DOWNLOAD2_E_NO_EXT_MMAGIC) {
$this->assertTrue(false, $e->getMessage());
}
unset($h, $e);
Expand Down

0 comments on commit 282645a

Please sign in to comment.