cvs: pear /PHP_Archive/Archive Creator.php
| From: | Greg Beaver | Date: | Tue, 12 Apr 2005 05:07:40 +0000 |
| Subject: | cvs: pear /PHP_Archive/Archive Creator.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-31116@lists.php.net to get a copy of this message | ||
cellog Tue Apr 12 01:07:40 2005 EDT
Modified files:
/pear/PHP_Archive/Archive Creator.php
Log:
add magicrequire so that require_once/include_once
have phar://$magicrequire/ prepended to the filename.
This should make pharring apps simpler if they adhere
to PEAR standards
http://cvs.php.net/diff.php/pear/PHP_Archive/Archive/Creator.php?r1=1.6&r2=1.7&ty=u
Index: pear/PHP_Archive/Archive/Creator.php
diff -u pear/PHP_Archive/Archive/Creator.php:1.6 pear/PHP_Archive/Archive/Creator.php:1.7
--- pear/PHP_Archive/Archive/Creator.php:1.6 Mon Apr 11 01:23:16 2005
+++ pear/PHP_Archive/Archive/Creator.php Tue Apr 12 01:07:40 2005
@@ -31,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.6 2005/04/11 05:23:16 cellog Exp $
+ * @version $Id: Creator.php,v 1.7 2005/04/12 05:07:40 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
@@ -120,7 +120,7 @@
if (!$allow_direct_access) {
$unpack_code .= <<<PHP
-require_once 'phar://$init_file';
+require_once 'phar://' . basename(__FILE__) . '/$init_file';
PHP;
} else {
if ($allow_direct_access) {
@@ -171,19 +171,9 @@
* @return boolean
*/
- function addFile($file, $save_path)
+ function addFile($file, $save_path, $magicrequire = false)
{
- $file_contents = file_get_contents($file);
- if ($this->compress) {
- $file_contents = '1' . base64_encode(
- pack("C1C1C1C1VC1C1", 0x1f, 0x8b, 8, 0, time(), 2, 0xFF) .
- gzdeflate($file_contents, 9) .
- pack("VV",crc32($file_contents),strlen($file_contents)));
- } else {
- $file_contents = '0' . $file_contents;
- }
- clearstatcache(); // a newly created archive could be erased if this is not performed
- return $this->tar->addString($save_path, $file_contents);
+ return $this->addString(file_get_contents($file), $save_path, $magicrequire);
}
/**
@@ -194,8 +184,14 @@
* @return boolean
*/
- function addString($file_contents, $save_path)
+ function addString($file_contents, $save_path, $magicrequire = false)
{
+ if ($magicrequire) {
+ $file_contents = str_replace("require_once '", "require_once
'phar://$magicrequire/",
+ $file_contents);
+ $file_contents = str_replace("include_once '", "include_once
'phar://$magicrequire/",
+ $file_contents);
+ }
if ($this->compress) {
$file_contents = '1' . base64_encode(
pack("C1C1C1C1VC1C1", 0x1f, 0x8b, 8, 0, time(), 2, 0xFF) .
@@ -401,18 +397,20 @@
/**
* Add a directory to the archive
*
- * @param string $dir The directory path to add
- * @param array files to ignore
- * @param array files to include (all others ignored)
+ * @param string The directory path to add
+ * @param array files to ignore
+ * @param array files to include (all others ignored)
+ * @param bool If set, then "require_once '" will be replaced with
+ * "require_once 'phar://$magicrequire/"
* @return boolean
*/
- function addDir($dir, $ignore = array(), $include = array())
+ function addDir($dir, $ignore = array(), $include = array(), $magicrequire = false)
{
$this->_setupIgnore($ignore, 1);
$this->_setupIgnore($include, 0);
$list = $this->dirList($dir);
- return $this->addArray($list);
+ return $this->addArray($list, $magicrequire);
}
/**
@@ -422,14 +420,13 @@
* @return boolean
*/
- function addArray($files)
+ function addArray($files, $magicrequire = false)
{
if (!is_array($files) || empty($files)) {
return false;
}
- $this->modified = true;
foreach ($files as $file_path => $save_path) {
- $returns[] = $this->addFile($file_path, $save_path, $compress);
+ $returns[] = $this->addFile($file_path, $save_path, $magicrequire);
}
return !in_array(false, $returns);
}