cvs: pear /PHP_Archive/Archive Creator.php Exception.php Manager.php

From: Date: Thu, 15 Dec 2005 05:33:32 +0000
Subject: cvs: pear /PHP_Archive/Archive Creator.php Exception.php Manager.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-36875@lists.php.net to get a copy of this message
cellog Thu Dec 15 05:33:32 2005 EDT Added files: /pear/PHP_Archive/Archive Exception.php Manager.php Modified files: /pear/PHP_Archive/Archive Creator.php Log: add beginnings of .phar manager for debugging phars

http://cvs.php.net/viewcvs.cgi/pear/PHP_Archive/Archive/Creator.php?r1=1.20&r2=1.21&diff_format=u Index: pear/PHP_Archive/Archive/Creator.php diff -u pear/PHP_Archive/Archive/Creator.php:1.20 pear/PHP_Archive/Archive/Creator.php:1.21 --- pear/PHP_Archive/Archive/Creator.php:1.20 Wed Dec 14 03:41:45 2005 +++ pear/PHP_Archive/Archive/Creator.php Thu Dec 15 05:33:31 2005 @@ -23,7 +23,7 @@ * @author Davey Shafik <davey@synapticmedia.net> * @author Greg Beaver <cellog@php.net> * @link http://www.synapticmedia.net Synaptic Media - * @version $Id: Creator.php,v 1.20 2005/12/14 03:41:45 cellog Exp $ + * @version $Id: Creator.php,v 1.21 2005/12/15 05:33:31 cellog Exp $ * @package PHP_Archive * @category PHP */ @@ -90,21 +90,17 @@ /** * PHP_Archive Constructor * - * @param string $init_file Init file (file called by default upon PHAR execution) + * @param string|false $init_file Init file (file called by default upon PHAR execution). + * if false, none will be called, and execution will return. + * use this option for libraries * @param boolean $compress Whether to compress the files or not (will cause slowdown!) - * @param mixed $allow_direct_access The file extension to prepend to requests for files - * (i.e. request is /index, this is .php or .htm or - * whatever), false means that users can't browse to - * any file but the init file (you should handle other - * pages in your init file code). If you set it to True, - * then the exact PATH_INFO is used * @param string $alias alias name like "go-pear.phar" to be used for opening * files from this phar * @param bool $relyOnPhar if true, then a slim, phar extension-dependent .phar will be * created */ - public function __construct($init_file = 'index.php', $compress = false, - $allow_direct_access = false, $alias = null, $relyOnPhar = false) + public function __construct($init_file = 'index.php', $compress = false, $alias = null, + $relyOnPhar = false) { $this->compress = $compress; $this->temp_path = System::mktemp(array('-d', 'phr')); @@ -141,32 +137,14 @@ $alias = $this->alias ? $this->alias : '@ALIAS@'; $unpack_code .= 'PHP_Archive::mapPhar("' . addslashes($alias) . '", ' . ($compress ? 'true' : 'false') . (!$relyOnPhar ? ', __FILE__, __COMPILER_HALT_OFFSET__' : '') . ');'; - if (!$allow_direct_access) { - $unpack_code .= <<<PHP + if ($init_file) { + $unpack_code .= ' -require_once 'phar://' . basename(__FILE__) . '/$init_file'; -PHP; - } else { - if ($allow_direct_access) { - $allow_direct_access = ''; - } elseif ($allow_direct_access{0} != '.') { - $allow_direct_access = '.' . $allow_direct_access; - } - $unpack_code .= <<<PHP - -require_once 'phar://{$_SERVER['PATH_INFO']}$allow_direct_access'; -PHP; +require_once \'phar://@ALIAS@/' . addslashes($init_file) . '\'; +'; } - $unpack_code .= <<<PHP - -if (count(get_included_files()) > 1) { - return; -} else { - exit; -} -?> -<?php __HALT_COMPILER(); +__HALT_COMPILER(); PHP; file_put_contents($this->temp_path . DIRECTORY_SEPARATOR . 'loader.php', $unpack_code); } @@ -464,12 +442,11 @@ if (!$newfile) { return false; } - $loader = fopen($this->temp_path . DIRECTORY_SEPARATOR . 'loader.php', 'rb'); if (isset($this->alias)) { - stream_copy_to_stream($loader, $newfile); - fclose($loader); + $loader = file_get_contents($this->temp_path . DIRECTORY_SEPARATOR . 'loader.php'); + $loader = str_replace('@ALIAS@', addslashes($this->alias), $loader); + fwrite($newfile, $loader); } else { - fclose($loader); $loader = file_get_contents($this->temp_path . DIRECTORY_SEPARATOR . 'loader.php'); $loader = str_replace('@ALIAS@', addslashes(basename($file_path)), $loader); fwrite($newfile, $loader); http://cvs.php.net/viewcvs.cgi/pear/PHP_Archive/Archive/Exception.php?view=markup&rev=1.1 Index: pear/PHP_Archive/Archive/Exception.php +++ pear/PHP_Archive/Archive/Exception.php <?php /** * PHP_Archive Manager Class creator (allows debugging/manipulation of phar files) * * @package PHP_Archive * @category PHP */ /** * base class for all PEAR exceptions */ require_once 'PEAR/Exception.php'; class PHP_Archive_Exception extends PEAR_Exception {} ?> http://cvs.php.net/viewcvs.cgi/pear/PHP_Archive/Archive/Manager.php?view=markup&rev=1.1 Index: pear/PHP_Archive/Archive/Manager.php +++ pear/PHP_Archive/Archive/Manager.php <?php /** * PHP_Archive Manager Class creator (allows debugging/manipulation of phar files) * * @package PHP_Archive * @category PHP */ /** * Needed for file manipulation */ require_once 'System.php'; /** * * @copyright Copyright © Gregory Beaver * @author Greg Beaver <cellog@php.net> * @version $Id: Manager.php,v 1.1 2005/12/15 05:33:31 cellog Exp $ * @package PHP_Archive * @category PHP */ class PHP_Archive_Manager { private $_archiveName; private $_compressed; private $_version = 'unknown'; private $_manifest; private $_fileStart; /** * Locate the .phar archive in the include_path and detect the file to open within * the archive. * * Possible parameters are phar://filename_within_phar.ext or * phar://pharname.phar/filename_within_phar.ext * * phar://filename_within_phar.ext will simply use the last .phar opened. * @param string a file within the archive * @return string the filename within the .phar to retrieve */ public function __construct($phar, $compressed = false) { $this->_archiveName = $phar; $this->_compressed = $compressed; $fp = fopen($this->_archiveName, 'rb'); $header = fread($fp, strlen('<?php #PHP_ARCHIVE_HEADER-')); if ($header == '<?php #PHP_ARCHIVE_HEADER-') { $version = ''; while (!feof($fp) && $c = fgetc($fp)) { $version .= $c; } if (version_compare($version, '0.7', '<')) { require_once 'PHP/Archive/Exception.php'; throw new PHP_Archive_Exception($phar . ' was created with obsolete PHP_Archive'); } $this->_version = $version; } // seek to __HALT_COMPILER_OFFSET__ $prev = ''; while (!feof($fp) && false != ($next = fread($fp, 8092))) { $prev .= $next; if (false != ($t = strpos($prev, '__HALT_COMPILER();'))) { if ($t + strlen('__HALT_COMPILER();') - strlen($next)) { // seek backwards to location fseek($fp, $t + strlen('__HALT_COMPILER();') - strlen($next), SEEK_CUR); } break; } $prev = $next; } $manifest_length = unpack('Vlen', fread($fp, 4)); $this->_manifest = $this->_unserializeManifest(fread($fp, $manifest_length['len'])); $this->_fileStart = ftell($fp); fclose($fp); } /** * Display information on a phar * */ public function dump() { } /** * Extract the .phar to a particular location * * @param string $toHere */ public function unPhar($toHere) { } /** * Re-make the phar from a previously after having done work on an unPharred phar * * @param string $fromHere */ public function rePhar($fromHere) { } /** * Enter description here... * * @param unknown_type $manifest * @return unknown */ private function _unserializeManifest($manifest) { // retrieve the number of files in the manifest $info = unpack('V', substr($manifest, 0, 4)); $manifest = substr($manifest, 4); $ret = array(); for ($i = 0; $i < $info[1]; $i++) { // length of the file name $len = unpack('V', substr($manifest, 0, 4)); // file name $savepath = substr($manifest, 4, $len[1]); $manifest = substr($manifest, $len[1] + 4); // retrieve manifest data: // 0 = uncompressed file size // 1 = timestamp of when file was added to phar // 2 = offset of file within phar relative to internal file's start // 3 = compressed file size (actual size in the phar) $ret[$savepath] = array_values(unpack('Va/Vb/Vc/Vd', substr($manifest, 0, 16))); $manifest = substr($manifest, 16); } return $ret; } } ?>
« previous php.pear.cvs (#36875) next »