cvs: pear /PHP_Archive Archive.php package.xml /PHP_Archive/Archive Creator.php /PHP_Archive/tests test.php test_phar.phar test_phar2.phar
| From: | Greg Beaver | Date: | Fri, 08 Apr 2005 04:53:42 +0000 |
| Subject: | cvs: pear /PHP_Archive Archive.php package.xml /PHP_Archive/Archive Creator.php /PHP_Archive/tests test.php test_phar.phar test_phar2.phar | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-31044@lists.php.net to get a copy of this message | ||
cellog Fri Apr 8 00:53:42 2005 EDT
Modified files:
/pear/PHP_Archive Archive.php package.xml
/pear/PHP_Archive/Archive Creator.php
/pear/PHP_Archive/tests test.php test_phar.phar test_phar2.phar
Log:
complete testing
now PHP_Archive bundles itself -
.phars are self-contained
add support for multiple phars:
phar://name.phar/file.php
phar://secondfile.phar/file.php
both of these can work!
http://cvs.php.net/diff.php/pear/PHP_Archive/Archive.php?r1=1.2&r2=1.3&ty=u Index: pear/PHP_Archive/Archive.php diff -u pear/PHP_Archive/Archive.php:1.2 pear/PHP_Archive/Archive.php:1.3 --- pear/PHP_Archive/Archive.php:1.2 Thu Apr 7 22:26:12 2005 +++ pear/PHP_Archive/Archive.php Fri Apr 8 00:53:39 2005 @@ -4,21 +4,10 @@ * * @package PHP_Archive * @category PHP + * @todo implement phar://basenamefile.phar/path/to/file.php */ /** - * Directory that contains this file - */ - -define('PHP_ARCHIVE_BASEDIR', dirname(__FILE__)); - -/** - * Data Directory for PHP_Archive - */ - -define('PHP_ARCHIVE_DATA_DIR', PHP_ARCHIVE_BASEDIR . DIRECTORY_SEPARATOR .'..'. DIRECTORY_SEPARATOR .'data'. DIRECTORY_SEPARATOR .'PHP_Archive'. DIRECTORY_SEPARATOR .'data'); - -/** * PHP_Archive Class (implements .phar) * * PHAR files a singular archive from which an entire application can run. @@ -26,10 +15,12 @@ * URIs to your includes. i.e. require_once 'phar://config.php' will include config.php * from the root of the PHAR file. * + * Tar/Gz code borrowed from the excellent File_Archive package by Vincent Lascaux. + * * @copyright Copyright © David Shafik and Synaptic Media 2004. All rights reserved. * @author Davey Shafik <davey@synapticmedia.net> * @link http://www.synapticmedia.net Synaptic Media - * @version $Id: Archive.php,v 1.2 2005/04/08 02:26:12 cellog Exp $ + * @version $Id: Archive.php,v 1.3 2005/04/08 04:53:39 cellog Exp $ * @package PHP_Archive * @category PHP */ @@ -39,16 +30,35 @@ /** * @var string Archive filename */ - - var $archive_name = null; + + var $archiveName = null; + + /** + * Current Stat info of the current file in the tar + */ + var $currentStat = null; + + /** + * Current file name in the tar + * @var string + */ + var $currentFilename = null; - var $internalFileLength = null; + /** - * @var object Archive_Tar object + * Length of the current tar file + * @var int */ - - var $archive = null; + + var $internalFileLength = 0; + + /** + * Length of the current tar file's footer + * @var int + */ + + var $footerLength = 0; /** * @var string Content of the file being requested @@ -61,23 +71,6 @@ */ var $position = 0; - - /** - * Start the stream - * - * Opens the PHP Archive, which is the file being called - */ - - function stream_start() - { - $aname = get_included_files(); - array_pop($aname); - $this->archive_name = array_pop($aname); - require_once 'PEAR.php'; -// require_once 'Archive/Tar.php'; -// $this->archive = new Archive_Tar($this->archive_name); - return true; - } function _processFile($path) { @@ -85,7 +78,7 @@ return ''; } $std = str_replace("\\", "/", $path); - while ($std != ($std = preg_replace("/[^\/:?]+\/\.\.\//", "", $std))) ; + while ($std != ($std = ereg_replace("[^\/:?]+/\.\./", "", $std))) ; $std = str_replace("/./", "", $std); if (strncmp($std, "./", 2) == 0) { return substr($std, 2); @@ -98,29 +91,21 @@ { $std = $this->_processFile($path); while (($error = $this->_nextFile()) === true) { - $sourceName = $this->currentFilename; if (empty($std) || $std == $this->currentFilename || //$std is a directory - strncmp($std.'/', $sourceName, strlen($std)+1) == 0) { + strncmp($std.'/', $this->currentFilename, strlen($std)+1) == 0) { return true; } } return $error; } - function _open() - { - $this->_file = @fopen($this->archive_name, "rb"); - if (!$this->_file) { - return PEAR::raiseError('Error: cannot open phar "' . $this->archive_name . '"'); - } - } - function _nextFile() { + @fread($this->_file, $this->internalFileLength + $this->footerLength); $rawHeader = @fread($this->_file, 512); if (strlen($rawHeader) < 512 || $rawHeader == pack("a512", "")) { - return PEAR::raiseError('Error: phar "' . $this->archive_name . '" has no tar header'); + 'Error: phar "' . $this->archiveName . '" has no tar header'; } $header = unpack( @@ -145,28 +130,71 @@ $this->currentFilename = $this->_processFile($header['path'] . $header['filename']); $checksum = 8 * ord(" "); - for ($i = 0; $i < 148; $i++) { - $checksum += ord($rawHeader{$i}); - } - for ($i = 156; $i < 512; $i++) { - $checksum += ord($rawHeader{$i}); + if (version_compare(phpversion(), '5.0.0', '>=')) { + $c1 = str_split(substr($rawHeader, 0, 512)); + $checkheader = array_merge(array_slice($c1, 0, 148), array_slice($c1, 156)); + if (!function_exists('_PharDoChecksum')) { + function _PharDoChecksum($a, $b) {return $a + ord($b);} + } + $checksum += array_reduce($checkheader, '_PharDoChecksum'); + } else { + for ($i = 0; $i < 148; $i++) { + $checksum += ord($rawHeader{$i}); + } + for ($i = 156; $i < 512; $i++) { + $checksum += ord($rawHeader{$i}); + } } if (octdec($header['checksum']) != $checksum) { - return PEAR::raiseError('Error: phar "' . - $this->archive_name . '" Checksum error on entry "' . $this->currentFilename . '"'); + return 'Error: phar "' . + $this->archiveName . '" Checksum error on entry "' . $this->currentFilename . '"'; } return true; } function extractFile($path) { - $this->_open(); - if ($this->_selectFile($path)) { - $actualLength = $this->internalFileLength; - $data = @fread($this->_file, $actualLength); + $this->_file = @fopen($this->archiveName, "rb"); + if (!$this->_file) { + return array('Error: cannot open phar "' . $this->archiveName . '"'); + } + if (($e = $this->_selectFile($path)) === true) { + $data = @fread($this->_file, $this->internalFileLength); + @fclose($this->_file); return $data; + } else { + @fclose($this->_file); + return array($e); + } + } + + /** + * Start the stream + * + * Opens the PHP Archive, which is the file being called + * @param string + * @return bool + */ + + function initializeStream($file) + { + $aname = get_included_files(); + $this->archiveName = 'phar://'; + if (strpos($file, '.phar')) { + // grab the basename of the phar we want + $test = substr($file, 0, strpos($file, '.phar') + 5); + } else { + $test = false; + } + while (strpos($this->archiveName, 'phar://') === 0 && + (!$test || !strpos($this->archiveName, $test))) { + $this->archiveName = array_pop($aname); } + if ($test && $this->archiveName != 'phar://') { + $file = substr($file, strlen($test) + 1); + } + return $file; } /** @@ -178,17 +206,25 @@ function stream_open($file) { $path = substr($file, 7); - $this->stream_start(); - $this->file = $this->extractFile($path); + $path = $this->initializeStream($path); + if ($this->archiveName == 'phar://') { + trigger_error('Error: Unknown phar in "' . $file . '"', E_USER_ERROR); + } + if (is_array($this->file = $this->extractFile($path))) { + trigger_error($this->file[0], E_USER_ERROR); + return false; + } $compressed = $this->file ? (int) $this->file{0} : false; $this->file ? $this->file = substr($this->file, 1) : false; if ($compressed) { + if (!function_exists('gzinflate')) { + trigger_error('Error: zlib extension is not enabled - gzinflate() function needed' . + ' for compressed .phars'); + return false; + } $this->file = base64_decode($this->file); - // code borrowed from File_Archive_Reader_Gzip by Greg Beaver $header = substr($this->file, 0, 10); $temp = unpack("Vcrc32/Visize", substr($this->file, -8)); - $crc32 = $temp['crc32']; - $size = $temp['isize']; $id = @unpack("H2id1/H2id2/C1tmp/C1flags", substr($header, 0, 4)); if ($id['id1'] != "1f" || $id['id2'] != "8b") { @@ -197,12 +233,12 @@ } $this->file = gzinflate(substr($this->file, 10, strlen($this->file) - 8)); - if ($size != strlen($this->file)) { + if ($temp['isize'] != strlen($this->file)) { trigger_error("Not valid gz file (size error {$size} != " . strlen($this->file) . ")", E_USER_ERROR); return false; } - if ($crc32 != crc32($this->file)) { + if ($temp['crc32'] != crc32($this->file)) { trigger_error("Not valid gz file (checksum error)", E_USER_ERROR); return false; } @@ -222,8 +258,6 @@ function stream_read($count) { - static $i = 0; - $i++; $ret = substr($this->file, $this->position, $count); $this->position += strlen($ret); return $ret; @@ -255,11 +289,21 @@ } /** - * The result of an fstat call, returns no values + * The result of an fstat call, returns mod time from tar, and file size */ function stream_stat() { - return array(); + return array( + 'mtime' => $this->currentStat[9], + 'atime' => $this->currentStat[9], + 'ctime' => $this->currentStat[9], + 'size' => strlen($this->file), + ); + } + + function APIVersion() + { + return '0.5'; } } http://cvs.php.net/diff.php/pear/PHP_Archive/package.xml?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/package.xml diff -u pear/PHP_Archive/package.xml:1.1 pear/PHP_Archive/package.xml:1.2 --- pear/PHP_Archive/package.xml:1.1 Tue Jan 25 04:23:33 2005 +++ pear/PHP_Archive/package.xml Fri Apr 8 00:53:39 2005 @@ -11,16 +11,31 @@ <email>davey@php.net</email> <role>lead</role> </maintainer> + <maintainer> + <user>cellog</user> + <name>Greg Beaver</name> + <email>cellog@php.net</email> + <role>developer</role> + </maintainer> </maintainers> <release> - <version>0.4.0</version> - <date>2004-11-29</date> + <version>0.5.0</version> + <date>2005-04-07</date> <license>PHP License</license> <state>alpha</state> - <notes>Made PHP_Archive_Creator smarter</notes> + <notes> + * Full support for multiple .phars! phar://pharname.phar/file + and phar://phar2.phar/anotherfile will work now + * Fix gz compression + * remove Archive_Tar dep for non-creation + * remove preg dep for non-creation + * bundle PHP_Archive in all created .phars - standalone! Only + compressed .phars have a dep on zlib + </notes> <deps> <dep type="php" rel="ge" version="4.3.0" optional="no"/> - <dep type="pkg" rel="ge" version="1.2" optional="no">Archive_Tar</dep> + <dep type="pkg" rel="ge" version="1.3.5" optional="no">PEAR</dep> + <dep type="pkg" rel="ge" version="1.3.1" optional="no">Archive_Tar</dep> </deps> <filelist> <dir baseinstalldir="PHP" name="/"> @@ -96,6 +111,21 @@ </release> <changelog> <release> + <version>0.5.0</version> + <date>2005-04-07</date> + <license>PHP License</license> + <state>alpha</state> + <notes> + * Full support for multiple .phars! phar://pharname.phar/file + and phar://phar2.phar/anotherfile will work now + * Fix gz compression + * remove Archive_Tar dep for non-creation + * remove preg dep for non-creation + * bundle PHP_Archive in all created .phars - standalone! Only + compressed .phars have a dep on zlib + </notes> + </release> + <release> <version>0.4.0</version> <date>2004-11-29</date> <license>PHP License</license> http://cvs.php.net/diff.php/pear/PHP_Archive/Archive/Creator.php?r1=1.2&r2=1.3&ty=u Index: pear/PHP_Archive/Archive/Creator.php diff -u pear/PHP_Archive/Archive/Creator.php:1.2 pear/PHP_Archive/Archive/Creator.php:1.3 --- pear/PHP_Archive/Archive/Creator.php:1.2 Thu Apr 7 22:26:12 2005 +++ pear/PHP_Archive/Archive/Creator.php Fri Apr 8 00:53:41 2005 @@ -11,7 +11,12 @@ */ require_once 'PHP/Archive.php'; - + +/** + * Require System, for temporary dir functions + */ +require_once 'System.php'; + /** * Require Archive_Tar */ @@ -26,7 +31,7 @@ * @copyright Copyright © David Shafik and Synaptic Media 2004. All rights reserved. * @author Davey Shafik <davey@synapticmedia.net> * @link http://www.synapticmedia.net Synaptic Media - * @version $Id: Creator.php,v 1.2 2005/04/08 02:26:12 cellog Exp $ + * @version $Id: Creator.php,v 1.3 2005/04/08 04:53:41 cellog Exp $ * @package PHP_Archive * @category PHP * @example c:\web\php-cvs\pear\PHP_Archive\docs\examples\PHP_Archive_Creator_Example_1.php Example PHP_Archive_Creator usage @@ -87,8 +92,10 @@ function __construct($init_file = 'index.php', $compress = false, $allow_direct_access = false) { $this->compress = $compress; - $this->temp_path = tempnam(PHP_ARCHIVE_DATA_DIR, 'phr'); + $this->temp_path = System::mktemp('phr'); $tar = new Archive_Tar($this->temp_path); + $contents = trim(str_replace(array('<?php', '?>'), array('', ''), + file_get_contents(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'Archive.php'))); $unpack_code = <<<PHP @@ -99,8 +106,15 @@ -require_once 'PHP/Archive.php'; -stream_register_wrapper('phar', 'PHP_Archive'); +if (!class_exists('PHP_Archive')) { +$contents +} +if (PHP_Archive::APIVersion() != '0.5') { +die('Error: PHP_Archive must be API version 0.5 - use bundled PHP_Archive for success'); +} +if (!in_array('phar', stream_get_wrappers())) { + stream_wrapper_register('phar', 'PHP_Archive'); +} PHP; if (!$allow_direct_access) { @@ -125,7 +139,7 @@ exit; ?> PHP; - $tar->addString('<?php #PHP_ARCHIVE_HEADER-0.4.0.php', $unpack_code); + $tar->addString('<?php #PHP_ARCHIVE_HEADER-0.5.0.php', $unpack_code); $this->code = $unpack_code; @@ -209,7 +223,6 @@ function savePhar($file_path = null) { copy($this->temp_path, $file_path); - unlink($this->temp_path); } } http://cvs.php.net/diff.php/pear/PHP_Archive/tests/test.php?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/test.php diff -u pear/PHP_Archive/tests/test.php:1.1 pear/PHP_Archive/tests/test.php:1.2 --- pear/PHP_Archive/tests/test.php:1.1 Tue Jan 25 04:23:35 2005 +++ pear/PHP_Archive/tests/test.php Fri Apr 8 00:53:41 2005 @@ -2,7 +2,7 @@ echo __FILE__; -require 'phar://test_root.php'; +require 'phar://test_phar.phar/test_root.php'; echo __LINE__ . "\n"; require 'phar://subdir/test_subdir.php'; http://cvs.php.net/diff.php/pear/PHP_Archive/tests/test_phar.phar?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/test_phar.phar http://cvs.php.net/diff.php/pear/PHP_Archive/tests/test_phar2.phar?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/test_phar2.phar
http://cvs.php.net/diff.php/pear/PHP_Archive/Archive.php?r1=1.2&r2=1.3&ty=u Index: pear/PHP_Archive/Archive.php diff -u pear/PHP_Archive/Archive.php:1.2 pear/PHP_Archive/Archive.php:1.3 --- pear/PHP_Archive/Archive.php:1.2 Thu Apr 7 22:26:12 2005 +++ pear/PHP_Archive/Archive.php Fri Apr 8 00:53:39 2005 @@ -4,21 +4,10 @@ * * @package PHP_Archive * @category PHP + * @todo implement phar://basenamefile.phar/path/to/file.php */ /** - * Directory that contains this file - */ - -define('PHP_ARCHIVE_BASEDIR', dirname(__FILE__)); - -/** - * Data Directory for PHP_Archive - */ - -define('PHP_ARCHIVE_DATA_DIR', PHP_ARCHIVE_BASEDIR . DIRECTORY_SEPARATOR .'..'. DIRECTORY_SEPARATOR .'data'. DIRECTORY_SEPARATOR .'PHP_Archive'. DIRECTORY_SEPARATOR .'data'); - -/** * PHP_Archive Class (implements .phar) * * PHAR files a singular archive from which an entire application can run. @@ -26,10 +15,12 @@ * URIs to your includes. i.e. require_once 'phar://config.php' will include config.php * from the root of the PHAR file. * + * Tar/Gz code borrowed from the excellent File_Archive package by Vincent Lascaux. + * * @copyright Copyright © David Shafik and Synaptic Media 2004. All rights reserved. * @author Davey Shafik <davey@synapticmedia.net> * @link http://www.synapticmedia.net Synaptic Media - * @version $Id: Archive.php,v 1.2 2005/04/08 02:26:12 cellog Exp $ + * @version $Id: Archive.php,v 1.3 2005/04/08 04:53:39 cellog Exp $ * @package PHP_Archive * @category PHP */ @@ -39,16 +30,35 @@ /** * @var string Archive filename */ - - var $archive_name = null; + + var $archiveName = null; + + /** + * Current Stat info of the current file in the tar + */ + var $currentStat = null; + + /** + * Current file name in the tar + * @var string + */ + var $currentFilename = null; - var $internalFileLength = null; + /** - * @var object Archive_Tar object + * Length of the current tar file + * @var int */ - - var $archive = null; + + var $internalFileLength = 0; + + /** + * Length of the current tar file's footer + * @var int + */ + + var $footerLength = 0; /** * @var string Content of the file being requested @@ -61,23 +71,6 @@ */ var $position = 0; - - /** - * Start the stream - * - * Opens the PHP Archive, which is the file being called - */ - - function stream_start() - { - $aname = get_included_files(); - array_pop($aname); - $this->archive_name = array_pop($aname); - require_once 'PEAR.php'; -// require_once 'Archive/Tar.php'; -// $this->archive = new Archive_Tar($this->archive_name); - return true; - } function _processFile($path) { @@ -85,7 +78,7 @@ return ''; } $std = str_replace("\\", "/", $path); - while ($std != ($std = preg_replace("/[^\/:?]+\/\.\.\//", "", $std))) ; + while ($std != ($std = ereg_replace("[^\/:?]+/\.\./", "", $std))) ; $std = str_replace("/./", "", $std); if (strncmp($std, "./", 2) == 0) { return substr($std, 2); @@ -98,29 +91,21 @@ { $std = $this->_processFile($path); while (($error = $this->_nextFile()) === true) { - $sourceName = $this->currentFilename; if (empty($std) || $std == $this->currentFilename || //$std is a directory - strncmp($std.'/', $sourceName, strlen($std)+1) == 0) { + strncmp($std.'/', $this->currentFilename, strlen($std)+1) == 0) { return true; } } return $error; } - function _open() - { - $this->_file = @fopen($this->archive_name, "rb"); - if (!$this->_file) { - return PEAR::raiseError('Error: cannot open phar "' . $this->archive_name . '"'); - } - } - function _nextFile() { + @fread($this->_file, $this->internalFileLength + $this->footerLength); $rawHeader = @fread($this->_file, 512); if (strlen($rawHeader) < 512 || $rawHeader == pack("a512", "")) { - return PEAR::raiseError('Error: phar "' . $this->archive_name . '" has no tar header'); + 'Error: phar "' . $this->archiveName . '" has no tar header'; } $header = unpack( @@ -145,28 +130,71 @@ $this->currentFilename = $this->_processFile($header['path'] . $header['filename']); $checksum = 8 * ord(" "); - for ($i = 0; $i < 148; $i++) { - $checksum += ord($rawHeader{$i}); - } - for ($i = 156; $i < 512; $i++) { - $checksum += ord($rawHeader{$i}); + if (version_compare(phpversion(), '5.0.0', '>=')) { + $c1 = str_split(substr($rawHeader, 0, 512)); + $checkheader = array_merge(array_slice($c1, 0, 148), array_slice($c1, 156)); + if (!function_exists('_PharDoChecksum')) { + function _PharDoChecksum($a, $b) {return $a + ord($b);} + } + $checksum += array_reduce($checkheader, '_PharDoChecksum'); + } else { + for ($i = 0; $i < 148; $i++) { + $checksum += ord($rawHeader{$i}); + } + for ($i = 156; $i < 512; $i++) { + $checksum += ord($rawHeader{$i}); + } } if (octdec($header['checksum']) != $checksum) { - return PEAR::raiseError('Error: phar "' . - $this->archive_name . '" Checksum error on entry "' . $this->currentFilename . '"'); + return 'Error: phar "' . + $this->archiveName . '" Checksum error on entry "' . $this->currentFilename . '"'; } return true; } function extractFile($path) { - $this->_open(); - if ($this->_selectFile($path)) { - $actualLength = $this->internalFileLength; - $data = @fread($this->_file, $actualLength); + $this->_file = @fopen($this->archiveName, "rb"); + if (!$this->_file) { + return array('Error: cannot open phar "' . $this->archiveName . '"'); + } + if (($e = $this->_selectFile($path)) === true) { + $data = @fread($this->_file, $this->internalFileLength); + @fclose($this->_file); return $data; + } else { + @fclose($this->_file); + return array($e); + } + } + + /** + * Start the stream + * + * Opens the PHP Archive, which is the file being called + * @param string + * @return bool + */ + + function initializeStream($file) + { + $aname = get_included_files(); + $this->archiveName = 'phar://'; + if (strpos($file, '.phar')) { + // grab the basename of the phar we want + $test = substr($file, 0, strpos($file, '.phar') + 5); + } else { + $test = false; + } + while (strpos($this->archiveName, 'phar://') === 0 && + (!$test || !strpos($this->archiveName, $test))) { + $this->archiveName = array_pop($aname); } + if ($test && $this->archiveName != 'phar://') { + $file = substr($file, strlen($test) + 1); + } + return $file; } /** @@ -178,17 +206,25 @@ function stream_open($file) { $path = substr($file, 7); - $this->stream_start(); - $this->file = $this->extractFile($path); + $path = $this->initializeStream($path); + if ($this->archiveName == 'phar://') { + trigger_error('Error: Unknown phar in "' . $file . '"', E_USER_ERROR); + } + if (is_array($this->file = $this->extractFile($path))) { + trigger_error($this->file[0], E_USER_ERROR); + return false; + } $compressed = $this->file ? (int) $this->file{0} : false; $this->file ? $this->file = substr($this->file, 1) : false; if ($compressed) { + if (!function_exists('gzinflate')) { + trigger_error('Error: zlib extension is not enabled - gzinflate() function needed' . + ' for compressed .phars'); + return false; + } $this->file = base64_decode($this->file); - // code borrowed from File_Archive_Reader_Gzip by Greg Beaver $header = substr($this->file, 0, 10); $temp = unpack("Vcrc32/Visize", substr($this->file, -8)); - $crc32 = $temp['crc32']; - $size = $temp['isize']; $id = @unpack("H2id1/H2id2/C1tmp/C1flags", substr($header, 0, 4)); if ($id['id1'] != "1f" || $id['id2'] != "8b") { @@ -197,12 +233,12 @@ } $this->file = gzinflate(substr($this->file, 10, strlen($this->file) - 8)); - if ($size != strlen($this->file)) { + if ($temp['isize'] != strlen($this->file)) { trigger_error("Not valid gz file (size error {$size} != " . strlen($this->file) . ")", E_USER_ERROR); return false; } - if ($crc32 != crc32($this->file)) { + if ($temp['crc32'] != crc32($this->file)) { trigger_error("Not valid gz file (checksum error)", E_USER_ERROR); return false; } @@ -222,8 +258,6 @@ function stream_read($count) { - static $i = 0; - $i++; $ret = substr($this->file, $this->position, $count); $this->position += strlen($ret); return $ret; @@ -255,11 +289,21 @@ } /** - * The result of an fstat call, returns no values + * The result of an fstat call, returns mod time from tar, and file size */ function stream_stat() { - return array(); + return array( + 'mtime' => $this->currentStat[9], + 'atime' => $this->currentStat[9], + 'ctime' => $this->currentStat[9], + 'size' => strlen($this->file), + ); + } + + function APIVersion() + { + return '0.5'; } } http://cvs.php.net/diff.php/pear/PHP_Archive/package.xml?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/package.xml diff -u pear/PHP_Archive/package.xml:1.1 pear/PHP_Archive/package.xml:1.2 --- pear/PHP_Archive/package.xml:1.1 Tue Jan 25 04:23:33 2005 +++ pear/PHP_Archive/package.xml Fri Apr 8 00:53:39 2005 @@ -11,16 +11,31 @@ <email>davey@php.net</email> <role>lead</role> </maintainer> + <maintainer> + <user>cellog</user> + <name>Greg Beaver</name> + <email>cellog@php.net</email> + <role>developer</role> + </maintainer> </maintainers> <release> - <version>0.4.0</version> - <date>2004-11-29</date> + <version>0.5.0</version> + <date>2005-04-07</date> <license>PHP License</license> <state>alpha</state> - <notes>Made PHP_Archive_Creator smarter</notes> + <notes> + * Full support for multiple .phars! phar://pharname.phar/file + and phar://phar2.phar/anotherfile will work now + * Fix gz compression + * remove Archive_Tar dep for non-creation + * remove preg dep for non-creation + * bundle PHP_Archive in all created .phars - standalone! Only + compressed .phars have a dep on zlib + </notes> <deps> <dep type="php" rel="ge" version="4.3.0" optional="no"/> - <dep type="pkg" rel="ge" version="1.2" optional="no">Archive_Tar</dep> + <dep type="pkg" rel="ge" version="1.3.5" optional="no">PEAR</dep> + <dep type="pkg" rel="ge" version="1.3.1" optional="no">Archive_Tar</dep> </deps> <filelist> <dir baseinstalldir="PHP" name="/"> @@ -96,6 +111,21 @@ </release> <changelog> <release> + <version>0.5.0</version> + <date>2005-04-07</date> + <license>PHP License</license> + <state>alpha</state> + <notes> + * Full support for multiple .phars! phar://pharname.phar/file + and phar://phar2.phar/anotherfile will work now + * Fix gz compression + * remove Archive_Tar dep for non-creation + * remove preg dep for non-creation + * bundle PHP_Archive in all created .phars - standalone! Only + compressed .phars have a dep on zlib + </notes> + </release> + <release> <version>0.4.0</version> <date>2004-11-29</date> <license>PHP License</license> http://cvs.php.net/diff.php/pear/PHP_Archive/Archive/Creator.php?r1=1.2&r2=1.3&ty=u Index: pear/PHP_Archive/Archive/Creator.php diff -u pear/PHP_Archive/Archive/Creator.php:1.2 pear/PHP_Archive/Archive/Creator.php:1.3 --- pear/PHP_Archive/Archive/Creator.php:1.2 Thu Apr 7 22:26:12 2005 +++ pear/PHP_Archive/Archive/Creator.php Fri Apr 8 00:53:41 2005 @@ -11,7 +11,12 @@ */ require_once 'PHP/Archive.php'; - + +/** + * Require System, for temporary dir functions + */ +require_once 'System.php'; + /** * Require Archive_Tar */ @@ -26,7 +31,7 @@ * @copyright Copyright © David Shafik and Synaptic Media 2004. All rights reserved. * @author Davey Shafik <davey@synapticmedia.net> * @link http://www.synapticmedia.net Synaptic Media - * @version $Id: Creator.php,v 1.2 2005/04/08 02:26:12 cellog Exp $ + * @version $Id: Creator.php,v 1.3 2005/04/08 04:53:41 cellog Exp $ * @package PHP_Archive * @category PHP * @example c:\web\php-cvs\pear\PHP_Archive\docs\examples\PHP_Archive_Creator_Example_1.php Example PHP_Archive_Creator usage @@ -87,8 +92,10 @@ function __construct($init_file = 'index.php', $compress = false, $allow_direct_access = false) { $this->compress = $compress; - $this->temp_path = tempnam(PHP_ARCHIVE_DATA_DIR, 'phr'); + $this->temp_path = System::mktemp('phr'); $tar = new Archive_Tar($this->temp_path); + $contents = trim(str_replace(array('<?php', '?>'), array('', ''), + file_get_contents(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'Archive.php'))); $unpack_code = <<<PHP @@ -99,8 +106,15 @@ -require_once 'PHP/Archive.php'; -stream_register_wrapper('phar', 'PHP_Archive'); +if (!class_exists('PHP_Archive')) { +$contents +} +if (PHP_Archive::APIVersion() != '0.5') { +die('Error: PHP_Archive must be API version 0.5 - use bundled PHP_Archive for success'); +} +if (!in_array('phar', stream_get_wrappers())) { + stream_wrapper_register('phar', 'PHP_Archive'); +} PHP; if (!$allow_direct_access) { @@ -125,7 +139,7 @@ exit; ?> PHP; - $tar->addString('<?php #PHP_ARCHIVE_HEADER-0.4.0.php', $unpack_code); + $tar->addString('<?php #PHP_ARCHIVE_HEADER-0.5.0.php', $unpack_code); $this->code = $unpack_code; @@ -209,7 +223,6 @@ function savePhar($file_path = null) { copy($this->temp_path, $file_path); - unlink($this->temp_path); } } http://cvs.php.net/diff.php/pear/PHP_Archive/tests/test.php?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/test.php diff -u pear/PHP_Archive/tests/test.php:1.1 pear/PHP_Archive/tests/test.php:1.2 --- pear/PHP_Archive/tests/test.php:1.1 Tue Jan 25 04:23:35 2005 +++ pear/PHP_Archive/tests/test.php Fri Apr 8 00:53:41 2005 @@ -2,7 +2,7 @@ echo __FILE__; -require 'phar://test_root.php'; +require 'phar://test_phar.phar/test_root.php'; echo __LINE__ . "\n"; require 'phar://subdir/test_subdir.php'; http://cvs.php.net/diff.php/pear/PHP_Archive/tests/test_phar.phar?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/test_phar.phar http://cvs.php.net/diff.php/pear/PHP_Archive/tests/test_phar2.phar?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/test_phar2.phar