summaryrefslogtreecommitdiff
path: root/ext/phar/tests
diff options
context:
space:
mode:
authorGreg Beaver <cellog@php.net>2008-01-08 07:08:46 +0000
committerGreg Beaver <cellog@php.net>2008-01-08 07:08:46 +0000
commitb93b48663d910f96d705757b7b94be181c2a422e (patch)
tree392e2232ce1b517bae0d0e39ffbee9a9e5b857a1 /ext/phar/tests
parent2e8106960b396d04fe6e829817f8e1f625aaaa57 (diff)
downloadphp-git-b93b48663d910f96d705757b7b94be181c2a422e.tar.gz
complete set of new tests for zip-based phars (need to test compression for zip-based phars)
fix a whole bunch of zip-related bugs tar tests need some naming add phar information to error messages, fix existing tests to reflect this
Diffstat (limited to 'ext/phar/tests')
-rw-r--r--ext/phar/tests/033a.phpt2
-rwxr-xr-xext/phar/tests/create_path_error.phpt8
-rw-r--r--ext/phar/tests/tar/033a.phpt2
-rw-r--r--ext/phar/tests/tar/open_for_write_newfile.phpt2
-rw-r--r--ext/phar/tests/tar/phar_buildfromiterator5.phpt6
-rw-r--r--ext/phar/tests/tar/phar_buildfromiterator6.phpt6
-rw-r--r--ext/phar/tests/tar/phar_buildfromiterator7.phpt6
-rw-r--r--ext/phar/tests/tar/phar_buildfromiterator9.phpt6
-rwxr-xr-xext/phar/tests/tar/phar_stub_error.phpt2
-rw-r--r--ext/phar/tests/tar/rename.phpt2
-rw-r--r--ext/phar/tests/zip/033.phpt48
-rw-r--r--ext/phar/tests/zip/033a.phpt47
-rw-r--r--ext/phar/tests/zip/create_new_and_modify.phpt45
-rw-r--r--ext/phar/tests/zip/create_new_phar_b.phpt27
-rw-r--r--ext/phar/tests/zip/delete.phpt35
-rw-r--r--ext/phar/tests/zip/delete_in_phar.phpt51
-rw-r--r--ext/phar/tests/zip/delete_in_phar_b.phpt49
-rw-r--r--ext/phar/tests/zip/delete_in_phar_confirm.phpt53
-rw-r--r--ext/phar/tests/zip/frontcontroller.phar.inc13
-rw-r--r--ext/phar/tests/zip/frontcontroller.phar.zipbin0 -> 625 bytes
-rw-r--r--ext/phar/tests/zip/frontcontroller1.phar.phpt14
-rw-r--r--ext/phar/tests/zip/frontcontroller10.phar.inc20
-rw-r--r--ext/phar/tests/zip/frontcontroller10.phar.phpt17
-rw-r--r--ext/phar/tests/zip/frontcontroller10.phar.zipbin0 -> 471 bytes
-rw-r--r--ext/phar/tests/zip/frontcontroller11.phar.inc20
-rw-r--r--ext/phar/tests/zip/frontcontroller11.phar.phpt17
-rw-r--r--ext/phar/tests/zip/frontcontroller11.phar.zipbin0 -> 461 bytes
-rw-r--r--ext/phar/tests/zip/frontcontroller12.phar.inc20
-rw-r--r--ext/phar/tests/zip/frontcontroller12.phar.phpt17
-rw-r--r--ext/phar/tests/zip/frontcontroller12.phar.zipbin0 -> 465 bytes
-rw-r--r--ext/phar/tests/zip/frontcontroller13.phar.phpt17
-rw-r--r--ext/phar/tests/zip/frontcontroller14.phar.phpt14
-rw-r--r--ext/phar/tests/zip/frontcontroller15.phar.phpt17
-rw-r--r--ext/phar/tests/zip/frontcontroller16.phar.phpt14
-rw-r--r--ext/phar/tests/zip/frontcontroller17.phar.phpt15
-rw-r--r--ext/phar/tests/zip/frontcontroller18.phar.phpt15
-rw-r--r--ext/phar/tests/zip/frontcontroller19.phar.phpt15
-rw-r--r--ext/phar/tests/zip/frontcontroller2.phar.inc12
-rw-r--r--ext/phar/tests/zip/frontcontroller2.phar.phpt13
-rw-r--r--ext/phar/tests/zip/frontcontroller2.phar.zipbin0 -> 531 bytes
-rw-r--r--ext/phar/tests/zip/frontcontroller20.phar.phpt15
-rw-r--r--ext/phar/tests/zip/frontcontroller21.phar.phpt20
-rw-r--r--ext/phar/tests/zip/frontcontroller3.phar.inc12
-rw-r--r--ext/phar/tests/zip/frontcontroller3.phar.phpt16
-rw-r--r--ext/phar/tests/zip/frontcontroller3.phar.zipbin0 -> 562 bytes
-rw-r--r--ext/phar/tests/zip/frontcontroller4.phar.inc12
-rw-r--r--ext/phar/tests/zip/frontcontroller4.phar.phpt13
-rw-r--r--ext/phar/tests/zip/frontcontroller4.phar.zipbin0 -> 561 bytes
-rw-r--r--ext/phar/tests/zip/frontcontroller5.phar.inc12
-rw-r--r--ext/phar/tests/zip/frontcontroller5.phar.phpt13
-rw-r--r--ext/phar/tests/zip/frontcontroller5.phar.zipbin0 -> 554 bytes
-rw-r--r--ext/phar/tests/zip/frontcontroller6.phar.inc12
-rw-r--r--ext/phar/tests/zip/frontcontroller6.phar.phpt20
-rw-r--r--ext/phar/tests/zip/frontcontroller6.phar.zipbin0 -> 559 bytes
-rw-r--r--ext/phar/tests/zip/frontcontroller7.phar.inc12
-rw-r--r--ext/phar/tests/zip/frontcontroller7.phar.phpt13
-rw-r--r--ext/phar/tests/zip/frontcontroller7.phar.zipbin0 -> 559 bytes
-rw-r--r--ext/phar/tests/zip/frontcontroller8.phar.inc13
-rw-r--r--ext/phar/tests/zip/frontcontroller8.phar.phpt20
-rw-r--r--ext/phar/tests/zip/frontcontroller8.phar.zipbin0 -> 684 bytes
-rw-r--r--ext/phar/tests/zip/frontcontroller9.phar.inc14
-rw-r--r--ext/phar/tests/zip/frontcontroller9.phar.phpt16
-rw-r--r--ext/phar/tests/zip/frontcontroller9.phar.zipbin0 -> 697 bytes
-rw-r--r--ext/phar/tests/zip/make_invalid_tar.php.inc12
-rw-r--r--ext/phar/tests/zip/open_for_write_existing.phpt38
-rwxr-xr-xext/phar/tests/zip/open_for_write_existing_b.phpt49
-rwxr-xr-xext/phar/tests/zip/open_for_write_existing_c.phpt43
-rw-r--r--ext/phar/tests/zip/open_for_write_newfile.phpt40
-rwxr-xr-xext/phar/tests/zip/open_for_write_newfile_b.phpt56
-rwxr-xr-xext/phar/tests/zip/open_for_write_newfile_c.phpt50
-rwxr-xr-xext/phar/tests/zip/phar_begin_setstub_commit.phpt51
-rw-r--r--ext/phar/tests/zip/phar_buildfromiterator4.phpt66
-rw-r--r--ext/phar/tests/zip/phar_buildfromiterator5.phpt59
-rw-r--r--ext/phar/tests/zip/phar_buildfromiterator6.phpt60
-rw-r--r--ext/phar/tests/zip/phar_buildfromiterator7.phpt60
-rw-r--r--ext/phar/tests/zip/phar_buildfromiterator8.phpt73
-rw-r--r--ext/phar/tests/zip/phar_buildfromiterator9.phpt65
-rw-r--r--ext/phar/tests/zip/phar_commitwrite.phpt44
-rw-r--r--ext/phar/tests/zip/phar_copy.phpt56
-rw-r--r--ext/phar/tests/zip/phar_magic.phpt32
-rw-r--r--ext/phar/tests/zip/phar_setalias.phpt42
-rw-r--r--ext/phar/tests/zip/phar_setalias2.phpt51
-rwxr-xr-xext/phar/tests/zip/phar_stub_error.phpt62
-rw-r--r--ext/phar/tests/zip/refcount1.phpt71
-rwxr-xr-xext/phar/tests/zip/refcount1_5_2.phpt63
-rw-r--r--ext/phar/tests/zip/rename.phpt40
-rw-r--r--ext/phar/tests/zip/tarmaker.php.inc70
87 files changed, 2132 insertions, 21 deletions
diff --git a/ext/phar/tests/033a.phpt b/ext/phar/tests/033a.phpt
index 1df67f5a16..6fbc0db365 100644
--- a/ext/phar/tests/033a.phpt
+++ b/ext/phar/tests/033a.phpt
@@ -32,5 +32,5 @@ unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php
?>
--EXPECTF--
bool(false)
-Cannot modify permissions for file "a.php" write operations are prohibited
+Cannot modify permissions for file "a.php" in phar "%s033a.1.phar.php", write operations are prohibited
===DONE===
diff --git a/ext/phar/tests/create_path_error.phpt b/ext/phar/tests/create_path_error.phpt
index 1ba89d759b..d3fc035860 100755
--- a/ext/phar/tests/create_path_error.phpt
+++ b/ext/phar/tests/create_path_error.phpt
@@ -54,9 +54,9 @@ foreach($checks as $check)
--EXPECTF--
string(5) "query"
string(5) "query"
-Error: file_put_contents(phar://%s//): failed to open stream: phar error: file "" cannot be empty
-Error: file_put_contents(phar://%s/.): failed to open stream: phar error: file "" cannot be empty
-Error: file_put_contents(phar://%s/../): failed to open stream: phar error: file "" cannot be empty
-Error: file_put_contents(phar://%s/a/..): failed to open stream: phar error: file "" cannot be empty
+Error: file_put_contents(phar://%s//): failed to open stream: phar error: file "" in phar "%s" cannot be empty
+Error: file_put_contents(phar://%s/.): failed to open stream: phar error: file "" in phar "%s" cannot be empty
+Error: file_put_contents(phar://%s/../): failed to open stream: phar error: file "" in phar "%s" cannot be empty
+Error: file_put_contents(phar://%s/a/..): failed to open stream: phar error: file "" in phar "%s" cannot be empty
Exception: Entry a does not exist and cannot be created: phar error: invalid path "a" contains illegal character
===DONE===
diff --git a/ext/phar/tests/tar/033a.phpt b/ext/phar/tests/tar/033a.phpt
index 69bf684bbf..469dbfb94c 100644
--- a/ext/phar/tests/tar/033a.phpt
+++ b/ext/phar/tests/tar/033a.phpt
@@ -42,5 +42,5 @@ unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php
?>
--EXPECTF--
bool(false)
-Cannot modify permissions for file "a.php" write operations are prohibited
+Cannot modify permissions for file "a.php" in phar "%s033a.1.phar.php", write operations are prohibited
===DONE===
diff --git a/ext/phar/tests/tar/open_for_write_newfile.phpt b/ext/phar/tests/tar/open_for_write_newfile.phpt
index dafbab8ac7..904f245b05 100644
--- a/ext/phar/tests/tar/open_for_write_newfile.phpt
+++ b/ext/phar/tests/tar/open_for_write_newfile.phpt
@@ -1,5 +1,5 @@
--TEST--
-Phar: fopen a .phar for writing (new file)
+Phar: fopen a .phar for writing (new file) tar-based
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
--INI--
diff --git a/ext/phar/tests/tar/phar_buildfromiterator5.phpt b/ext/phar/tests/tar/phar_buildfromiterator5.phpt
index 3bd2cec78c..600bd2ee5c 100644
--- a/ext/phar/tests/tar/phar_buildfromiterator5.phpt
+++ b/ext/phar/tests/tar/phar_buildfromiterator5.phpt
@@ -1,5 +1,5 @@
--TEST--
-Phar::buildFromIterator() iterator, iterator returns non-string
+Phar::buildFromIterator() iterator, iterator returns non-string tar-based
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
--INI--
@@ -37,7 +37,7 @@ class myIterator implements Iterator
}
try {
chdir(dirname(__FILE__));
- $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar');
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar');
var_dump($phar->buildFromIterator(new myIterator(array('a' => new stdClass))));
} catch (Exception $e) {
var_dump(get_class($e));
@@ -47,7 +47,7 @@ try {
===DONE===
--CLEAN--
<?php
-unlink(dirname(__FILE__) . '/buildfromiterator.phar');
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.tar');
__HALT_COMPILER();
?>
--EXPECTF--
diff --git a/ext/phar/tests/tar/phar_buildfromiterator6.phpt b/ext/phar/tests/tar/phar_buildfromiterator6.phpt
index ae73bbd479..e891a5d065 100644
--- a/ext/phar/tests/tar/phar_buildfromiterator6.phpt
+++ b/ext/phar/tests/tar/phar_buildfromiterator6.phpt
@@ -1,5 +1,5 @@
--TEST--
-Phar::buildFromIterator() iterator, key is int
+Phar::buildFromIterator() iterator, key is int tar-based
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
--INI--
@@ -37,7 +37,7 @@ class myIterator implements Iterator
}
try {
chdir(dirname(__FILE__));
- $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar');
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar');
var_dump($phar->buildFromIterator(new myIterator(array(basename(__FILE__, 'php') . 'phpt'))));
} catch (Exception $e) {
var_dump(get_class($e));
@@ -47,7 +47,7 @@ try {
===DONE===
--CLEAN--
<?php
-unlink(dirname(__FILE__) . '/buildfromiterator.phar');
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.tar');
__HALT_COMPILER();
?>
--EXPECTF--
diff --git a/ext/phar/tests/tar/phar_buildfromiterator7.phpt b/ext/phar/tests/tar/phar_buildfromiterator7.phpt
index 38d2e1a5f2..d64c032d71 100644
--- a/ext/phar/tests/tar/phar_buildfromiterator7.phpt
+++ b/ext/phar/tests/tar/phar_buildfromiterator7.phpt
@@ -1,5 +1,5 @@
--TEST--
-Phar::buildFromIterator() iterator, file can't be opened
+Phar::buildFromIterator() iterator, file can't be opened tar-based
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
--INI--
@@ -37,7 +37,7 @@ class myIterator implements Iterator
}
try {
chdir(dirname(__FILE__));
- $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar');
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar');
var_dump($phar->buildFromIterator(new myIterator(array('a' => basename(__FILE__, 'php') . '/oopsie/there.phpt'))));
} catch (Exception $e) {
var_dump(get_class($e));
@@ -47,7 +47,7 @@ try {
===DONE===
--CLEAN--
<?php
-unlink(dirname(__FILE__) . '/buildfromiterator.phar');
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.tar');
__HALT_COMPILER();
?>
--EXPECT--
diff --git a/ext/phar/tests/tar/phar_buildfromiterator9.phpt b/ext/phar/tests/tar/phar_buildfromiterator9.phpt
index 0b56307545..f9deef4d9f 100644
--- a/ext/phar/tests/tar/phar_buildfromiterator9.phpt
+++ b/ext/phar/tests/tar/phar_buildfromiterator9.phpt
@@ -1,5 +1,5 @@
--TEST--
-Phar::buildFromIterator() iterator, 1 file resource passed in
+Phar::buildFromIterator() iterator, 1 file resource passed in tar-based
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
--INI--
@@ -37,7 +37,7 @@ class myIterator implements Iterator
}
try {
chdir(dirname(__FILE__));
- $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar');
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar');
var_dump($phar->buildFromIterator(new myIterator(array('a' => $a = fopen(basename(__FILE__, 'php') . 'phpt', 'r')))));
fclose($a);
} catch (Exception $e) {
@@ -48,7 +48,7 @@ try {
===DONE===
--CLEAN--
<?php
-unlink(dirname(__FILE__) . '/buildfromiterator.phar');
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.tar');
__HALT_COMPILER();
?>
--EXPECTF--
diff --git a/ext/phar/tests/tar/phar_stub_error.phpt b/ext/phar/tests/tar/phar_stub_error.phpt
index c4cee768e8..0c4de9657a 100755
--- a/ext/phar/tests/tar/phar_stub_error.phpt
+++ b/ext/phar/tests/tar/phar_stub_error.phpt
@@ -1,5 +1,5 @@
--TEST--
-Phar::setStub()/getStub()
+Phar::setStub()/getStub() tar-based
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
--INI--
diff --git a/ext/phar/tests/tar/rename.phpt b/ext/phar/tests/tar/rename.phpt
index ed410a863a..e3e3dfa984 100644
--- a/ext/phar/tests/tar/rename.phpt
+++ b/ext/phar/tests/tar/rename.phpt
@@ -1,5 +1,5 @@
--TEST--
-Phar: rename test
+Phar: rename test tar-based
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
--INI--
diff --git a/ext/phar/tests/zip/033.phpt b/ext/phar/tests/zip/033.phpt
new file mode 100644
index 0000000000..3d0e584e64
--- /dev/null
+++ b/ext/phar/tests/zip/033.phpt
@@ -0,0 +1,48 @@
+--TEST--
+Phar::chmod zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.1.phar.php';
+$pname = 'phar://hio';
+
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('a.php', '<?php echo "This is a\n"; include "'.$pname.'/b.php"; ?>');
+$a->addFile('.phar/alias.txt', 'hio');
+$a->mkDir('test');
+$a->close();
+
+try {
+ $a = new Phar($fname);
+ var_dump($a['a.php']->isExecutable());
+ $a['a.php']->chmod(0777);
+ var_dump($a['a.php']->isExecutable());
+ $a['a.php']->chmod(0666);
+ var_dump($a['a.php']->isExecutable());
+ echo "test dir\n";
+ var_dump($a['test']->isDir());
+ var_dump($a['test']->isReadable());
+ $a['test']->chmod(0000);
+ var_dump($a['test']->isReadable());
+ $a['test']->chmod(0666);
+ var_dump($a['test']->isReadable());
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php');
+?>
+--EXPECTF--
+bool(false)
+Cannot modify permissions for file "a.php" in phar "%s033.1.phar.php", not supported for zip-based phars
+===DONE===
diff --git a/ext/phar/tests/zip/033a.phpt b/ext/phar/tests/zip/033a.phpt
new file mode 100644
index 0000000000..77f1925c9e
--- /dev/null
+++ b/ext/phar/tests/zip/033a.phpt
@@ -0,0 +1,47 @@
+--TEST--
+Phar::chmod zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.1.phar.php';
+$pname = 'phar://hio';
+
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('a.php', '<?php echo "This is a\n"; include "'.$pname.'/b.php"; ?>');
+$a->addFile('.phar/alias.txt', 'hio');
+$a->mkDir('test');
+$a->close();
+
+try {
+ $a = new Phar($fname);
+ var_dump($a['a.php']->isExecutable());
+ $a['a.php']->chmod(0777);
+ var_dump($a['a.php']->isExecutable());
+ $a['a.php']->chmod(0666);
+ var_dump($a['a.php']->isExecutable());
+ echo "test dir\n";
+ var_dump($a['test']->isExecutable());
+ $a['test']->chmod(0777);
+ var_dump($a['test']->isExecutable());
+ $a['test']->chmod(0666);
+ var_dump($a['test']->isExecutable());
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php');
+?>
+--EXPECTF--
+bool(false)
+Cannot modify permissions for file "a.php" in phar "%sa.1.phar.php", write operations are prohibited
+===DONE===
diff --git a/ext/phar/tests/zip/create_new_and_modify.phpt b/ext/phar/tests/zip/create_new_and_modify.phpt
new file mode 100644
index 0000000000..b81e5a779f
--- /dev/null
+++ b/ext/phar/tests/zip/create_new_and_modify.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Phar: create and modify zip-based phar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = 'phar://' . $fname;
+
+@unlink($fname);
+
+file_put_contents($pname . '/a.php', "brand new!\n");
+
+$phar = new Phar($fname);
+var_dump($phar->isZip());
+$sig1 = md5_file($fname);
+
+include $pname . '/a.php';
+
+file_put_contents($pname .'/a.php', "modified!\n");
+file_put_contents($pname .'/b.php', "another!\n");
+
+$phar = new Phar($fname);
+$sig2 = md5_file($fname);
+
+var_dump($sig1 != $sig2);
+
+include $pname . '/a.php';
+include $pname . '/b.php';
+
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+--EXPECTF--
+bool(true)
+brand new!
+bool(true)
+modified!
+another!
+===DONE===
diff --git a/ext/phar/tests/zip/create_new_phar_b.phpt b/ext/phar/tests/zip/create_new_phar_b.phpt
new file mode 100644
index 0000000000..5aec78d2b9
--- /dev/null
+++ b/ext/phar/tests/zip/create_new_phar_b.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Phar: create a completely new zip-based phar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=1
+--FILE--
+<?php
+
+file_put_contents('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip/a.php',
+ 'brand new!');
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip/a.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+
+Warning: file_put_contents(phar://%screate_new_phar_b.phar.zip/a.php): failed to open stream: phar error: write operations disabled by INI setting in %screate_new_phar_b.php on line %d
+
+Warning: include(phar://%screate_new_phar_b.phar.zip/a.php): failed to open stream: No such file or directory in %screate_new_phar_b.php on line %d
+
+Warning: include(): Failed opening 'phar://%screate_new_phar_b.phar.zip/a.php' for inclusion (include_path='%s') in %screate_new_phar_b.php on line %d
+
+===DONE===
diff --git a/ext/phar/tests/zip/delete.phpt b/ext/phar/tests/zip/delete.phpt
new file mode 100644
index 0000000000..77ae85f909
--- /dev/null
+++ b/ext/phar/tests/zip/delete.phpt
@@ -0,0 +1,35 @@
+--TEST--
+Phar: delete test, zip-based phar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('a', 'a');
+$a->addFile('.phar/stub.php', $file);
+$a->close();
+
+$phar = new Phar($fname);
+
+echo file_get_contents($pname . '/a') . "\n";
+$phar->delete('a');
+echo file_get_contents($pname . '/a') . "\n";
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+a
+
+Warning: file_get_contents(phar://%sdelete.phar.php/a): failed to open stream: phar error: "a" is not a file in phar "%sdelete.phar.php" in %sdelete.php on line %d \ No newline at end of file
diff --git a/ext/phar/tests/zip/delete_in_phar.phpt b/ext/phar/tests/zip/delete_in_phar.phpt
new file mode 100644
index 0000000000..ec743b53c4
--- /dev/null
+++ b/ext/phar/tests/zip/delete_in_phar.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Phar: delete a file within a zip-based .phar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('a.php', '<?php echo "This is a\n"; ?>');
+$a->addFile('b.php', '<?php echo "This is b\n"; ?>');
+$a->addFile('b/c.php', '<?php echo "This is b/c\n"; ?>');
+$a->addFile('.phar/stub.php', '<?php __HALT_COMPILER(); ?>');
+$a->close();
+
+include $pname . '/a.php';
+include $pname . '/b.php';
+include $pname . '/b/c.php';
+unlink($pname . '/b/c.php');
+?>
+===AFTER===
+<?php
+include $pname . '/a.php';
+include $pname . '/b.php';
+include $pname . '/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+This is a
+This is b
+This is b/c
+===AFTER===
+This is a
+This is b
+
+Warning: include(%sdelete_in_phar.phar.php/b/c.php): failed to open stream: phar error: "b/c.php" is not a file in phar "%sdelete_in_phar.phar.php" in %sdelete_in_phar.php on line %d
+
+Warning: include(): Failed opening 'phar://%sdelete_in_phar.phar.php/b/c.php' for inclusion (include_path='%s') in %sdelete_in_phar.php on line %d
+
+===DONE===
+ \ No newline at end of file
diff --git a/ext/phar/tests/zip/delete_in_phar_b.phpt b/ext/phar/tests/zip/delete_in_phar_b.phpt
new file mode 100644
index 0000000000..2816b10437
--- /dev/null
+++ b/ext/phar/tests/zip/delete_in_phar_b.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Phar: delete a file within a zip-based .phar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('a.php', '<?php echo "This is a\n"; ?>');
+$a->addFile('b.php', '<?php echo "This is b\n"; ?>');
+$a->addFile('b/c.php', '<?php echo "This is b/c\n"; ?>');
+$a->addFile('.phar/stub.php', '<?php __HALT_COMPILER(); ?>');
+$a->close();
+
+include $pname . '/a.php';
+include $pname . '/b.php';
+include $pname . '/b/c.php';
+unlink($pname . '/b/c.php');
+?>
+===AFTER===
+<?php
+include $pname . '/a.php';
+include $pname . '/b.php';
+include $pname . '/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+This is a
+This is b
+This is b/c
+
+Warning: unlink(): phar error: write operations disabled by INI setting in %sdelete_in_phar_b.php on line %d
+===AFTER===
+This is a
+This is b
+This is b/c
+
+===DONE===
diff --git a/ext/phar/tests/zip/delete_in_phar_confirm.phpt b/ext/phar/tests/zip/delete_in_phar_confirm.phpt
new file mode 100644
index 0000000000..9ffe718a85
--- /dev/null
+++ b/ext/phar/tests/zip/delete_in_phar_confirm.phpt
@@ -0,0 +1,53 @@
+--TEST--
+Phar: delete a file within a zip-based .phar (confirm disk file is changed)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('a.php', '<?php echo "This is a\n"; ?>');
+$a->addFile('b.php', '<?php echo "This is b\n"; ?>');
+$a->addFile('b/c.php', '<?php echo "This is b/c\n"; ?>');
+$a->addFile('.phar/stub.php', '<?php __HALT_COMPILER(); ?>');
+$a->close();
+include $pname . '/a.php';
+include $pname . '/b.php';
+include $pname . '/b/c.php';
+$md5 = md5_file($fname);
+unlink($pname . '/b/c.php');
+clearstatcache();
+$md52 = md5_file($fname);
+if ($md5 == $md52) echo 'file was not modified';
+?>
+===AFTER===
+<?php
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/a.php';
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b.php';
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+This is a
+This is b
+This is b/c
+===AFTER===
+This is a
+This is b
+
+Warning: include(%sdelete_in_phar_confirm.phar.php/b/c.php): failed to open stream: phar error: "b/c.php" is not a file in phar "%sdelete_in_phar_confirm.phar.php" in %sdelete_in_phar_confirm.php on line %d
+
+Warning: include(): Failed opening 'phar://%sdelete_in_phar_confirm.phar.php/b/c.php' for inclusion (include_path='%s') in %sdelete_in_phar_confirm.php on line %d
+
+===DONE===
diff --git a/ext/phar/tests/zip/frontcontroller.phar.inc b/ext/phar/tests/zip/frontcontroller.phar.inc
new file mode 100644
index 0000000000..241dceb57b
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller.phar.inc
@@ -0,0 +1,13 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller.phar.zip');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a['index.php'] = 'here is my index';
+$a->setStub('<?php
+Phar::webPhar();
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/frontcontroller.phar.zip b/ext/phar/tests/zip/frontcontroller.phar.zip
new file mode 100644
index 0000000000..4ee905dd3a
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/frontcontroller1.phar.phpt b/ext/phar/tests/zip/frontcontroller1.phar.phpt
new file mode 100644
index 0000000000..2be7ab478c
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller1.phar.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller other zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller1.phar.php/a.jpg
+REQUEST_URI=/frontcontroller1.phar.php/a.jpg
+--FILE_EXTERNAL--
+frontcontroller.phar.zip
+--EXPECTHEADERS--
+Content-type: image/jpeg
+Content-length: 3
+--EXPECT--
+hio
diff --git a/ext/phar/tests/zip/frontcontroller10.phar.inc b/ext/phar/tests/zip/frontcontroller10.phar.inc
new file mode 100644
index 0000000000..c973cc15d9
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller10.phar.inc
@@ -0,0 +1,20 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller10.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller10.phar.zip');
+$a['index.php'] = '<?php
+var_dump($_SERVER["PHP_SELF"]);
+var_dump($_SERVER["SCRIPT_NAME"]);
+var_dump($_SERVER["SCRIPT_FILENAME"]);
+var_dump($_SERVER["REQUEST_URI"]);
+var_dump($_SERVER["PHAR_PHP_SELF"]);
+var_dump($_SERVER["PHAR_SCRIPT_NAME"]);
+var_dump($_SERVER["PHAR_SCRIPT_FILENAME"]);
+var_dump($_SERVER["PHAR_REQUEST_URI"]);
+';
+$a->setStub('<?php
+Phar::mungServer(array("PHP_SELF", "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI", "OOPSIE"));
+Phar::webPhar();
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/frontcontroller10.phar.phpt b/ext/phar/tests/zip/frontcontroller10.phar.phpt
new file mode 100644
index 0000000000..025becd670
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller10.phar.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller rewrite array invalid zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller10.phar.php/hi
+REQUEST_URI=/frontcontroller10.phar.php/hi
+--FILE_EXTERNAL--
+frontcontroller4.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECTF--
+Fatal error: Uncaught exception 'UnexpectedValueException' with message 'phar rewrite value for "/hi" was not a string' in %sfrontcontroller10.phar.php:2
+Stack trace:
+#0 %sfrontcontroller10.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array, Array)
+#1 {main}
+ thrown in %sfrontcontroller10.phar.php on line 2 \ No newline at end of file
diff --git a/ext/phar/tests/zip/frontcontroller10.phar.zip b/ext/phar/tests/zip/frontcontroller10.phar.zip
new file mode 100644
index 0000000000..c37cb381fb
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller10.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/frontcontroller11.phar.inc b/ext/phar/tests/zip/frontcontroller11.phar.inc
new file mode 100644
index 0000000000..c24a6f14e4
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller11.phar.inc
@@ -0,0 +1,20 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller11.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller11.phar.zip');
+$a['index.php'] = '<?php
+var_dump($_SERVER["PHP_SELF"]);
+var_dump($_SERVER["SCRIPT_NAME"]);
+var_dump($_SERVER["SCRIPT_FILENAME"]);
+var_dump($_SERVER["REQUEST_URI"]);
+var_dump($_SERVER["PHAR_PHP_SELF"]);
+var_dump($_SERVER["PHAR_SCRIPT_NAME"]);
+var_dump($_SERVER["PHAR_SCRIPT_FILENAME"]);
+var_dump($_SERVER["PHAR_REQUEST_URI"]);
+';
+$a->setStub('<?php
+Phar::mungServer(array(array(), "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI"));
+Phar::webPhar();
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/frontcontroller11.phar.phpt b/ext/phar/tests/zip/frontcontroller11.phar.phpt
new file mode 100644
index 0000000000..789138f329
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller11.phar.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller mime type extension is not a string zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller11.phar.php/a.php
+REQUEST_URI=/frontcontroller11.phar.php/a.php
+--FILE_EXTERNAL--
+frontcontroller5.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECTF--
+Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Key of MIME type overrides array must be a file extension, was "0"' in %sfrontcontroller11.phar.php:2
+Stack trace:
+#0 %sfrontcontroller11.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
+#1 {main}
+ thrown in %sfrontcontroller11.phar.php on line 2 \ No newline at end of file
diff --git a/ext/phar/tests/zip/frontcontroller11.phar.zip b/ext/phar/tests/zip/frontcontroller11.phar.zip
new file mode 100644
index 0000000000..48e5fc678a
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller11.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/frontcontroller12.phar.inc b/ext/phar/tests/zip/frontcontroller12.phar.inc
new file mode 100644
index 0000000000..77c4a1dd0e
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller12.phar.inc
@@ -0,0 +1,20 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller12.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller12.phar.zip');
+$a['index.php'] = '<?php
+var_dump($_SERVER["PHP_SELF"]);
+var_dump($_SERVER["SCRIPT_NAME"]);
+var_dump($_SERVER["SCRIPT_FILENAME"]);
+var_dump($_SERVER["REQUEST_URI"]);
+var_dump($_SERVER["PHAR_PHP_SELF"]);
+var_dump($_SERVER["PHAR_SCRIPT_NAME"]);
+var_dump($_SERVER["PHAR_SCRIPT_FILENAME"]);
+var_dump($_SERVER["PHAR_REQUEST_URI"]);
+';
+$a->setStub('<?php
+Phar::mungServer(array("PHP_SELF", "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI"));
+Phar::webPhar();
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/frontcontroller12.phar.phpt b/ext/phar/tests/zip/frontcontroller12.phar.phpt
new file mode 100644
index 0000000000..1b5102aa19
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller12.phar.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller mime type unknown int zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller12.phar.php/a.php
+REQUEST_URI=/frontcontroller12.phar.php/a.php
+--FILE_EXTERNAL--
+frontcontroller6.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECTF--
+Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed' in %sfrontcontroller12.phar.php:2
+Stack trace:
+#0 %sfrontcontroller12.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
+#1 {main}
+ thrown in %sfrontcontroller12.phar.php on line 2 \ No newline at end of file
diff --git a/ext/phar/tests/zip/frontcontroller12.phar.zip b/ext/phar/tests/zip/frontcontroller12.phar.zip
new file mode 100644
index 0000000000..c086c4d4a4
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller12.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/frontcontroller13.phar.phpt b/ext/phar/tests/zip/frontcontroller13.phar.phpt
new file mode 100644
index 0000000000..5fc4b834e0
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller13.phar.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller mime type not string/int zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller13.phar.php/a.php
+REQUEST_URI=/frontcontroller13.phar.php/a.php
+--FILE_EXTERNAL--
+frontcontroller7.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECTF--
+Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed' in %sfrontcontroller13.phar.php:2
+Stack trace:
+#0 %sfrontcontroller13.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
+#1 {main}
+ thrown in %sfrontcontroller13.phar.php on line 2 \ No newline at end of file
diff --git a/ext/phar/tests/zip/frontcontroller14.phar.phpt b/ext/phar/tests/zip/frontcontroller14.phar.phpt
new file mode 100644
index 0000000000..7a3aaa57b2
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller14.phar.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller mime type override, other zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller14.phar.php/a.jpg
+REQUEST_URI=/frontcontroller14.phar.php/a.jpg
+--FILE_EXTERNAL--
+frontcontroller8.phar.zip
+--EXPECTHEADERS--
+Content-type: foo/bar
+Content-length: 4
+--EXPECT--
+hio2
diff --git a/ext/phar/tests/zip/frontcontroller15.phar.phpt b/ext/phar/tests/zip/frontcontroller15.phar.phpt
new file mode 100644
index 0000000000..33ac6739cd
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller15.phar.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller mime type override, Phar::PHPS zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller15.phar.php/a.php
+REQUEST_URI=/frontcontroller15.phar.php/a.php
+--FILE_EXTERNAL--
+frontcontroller8.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECT--
+<code><span style="color: #000000">
+<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
+</span>
+</code>
+
diff --git a/ext/phar/tests/zip/frontcontroller16.phar.phpt b/ext/phar/tests/zip/frontcontroller16.phar.phpt
new file mode 100644
index 0000000000..924996b00b
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller16.phar.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller mime type override, Phar::PHP zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller16.phar.php/a.phps
+REQUEST_URI=/frontcontroller16.phar.php/a.phps
+--FILE_EXTERNAL--
+frontcontroller8.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECT--
+hio1
+
diff --git a/ext/phar/tests/zip/frontcontroller17.phar.phpt b/ext/phar/tests/zip/frontcontroller17.phar.phpt
new file mode 100644
index 0000000000..36054b8971
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller17.phar.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller mime type unknown zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller17.phar.php/fronk.gronk
+REQUEST_URI=/frontcontroller17.phar.php/fronk.gronk
+--FILE_EXTERNAL--
+frontcontroller8.phar.zip
+--EXPECTHEADERS--
+Content-type: application/octet-stream
+Content-length: 4
+--EXPECT--
+hio3
+
diff --git a/ext/phar/tests/zip/frontcontroller18.phar.phpt b/ext/phar/tests/zip/frontcontroller18.phar.phpt
new file mode 100644
index 0000000000..8d9139820e
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller18.phar.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller $_SERVER munging failure zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller18.phar.php/fronk.gronk
+REQUEST_URI=/frontcontroller18.phar.php/fronk.gronk
+--FILE_EXTERNAL--
+frontcontroller9.phar.zip
+--EXPECTF--
+Fatal error: Uncaught exception 'UnexpectedValueException' with message 'No values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME' in %sfrontcontroller18.phar.php:2
+Stack trace:
+#0 %sfrontcontroller18.phar.php(2): Phar::mungServer(Array)
+#1 {main}
+ thrown in %sfrontcontroller18.phar.php on line 2
diff --git a/ext/phar/tests/zip/frontcontroller19.phar.phpt b/ext/phar/tests/zip/frontcontroller19.phar.phpt
new file mode 100644
index 0000000000..8057448a60
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller19.phar.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller $_SERVER munging failure 2 zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller19.phar.php/
+REQUEST_URI=/frontcontroller19.phar.php/
+--FILE_EXTERNAL--
+frontcontroller10.phar.zip
+--EXPECTF--
+Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Too many values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME' in %sfrontcontroller19.phar.php:2
+Stack trace:
+#0 %sfrontcontroller19.phar.php(2): Phar::mungServer(Array)
+#1 {main}
+ thrown in %sfrontcontroller19.phar.php on line 2
diff --git a/ext/phar/tests/zip/frontcontroller2.phar.inc b/ext/phar/tests/zip/frontcontroller2.phar.inc
new file mode 100644
index 0000000000..6cfa052a83
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller2.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller2.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller2.phar.zip');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "a.php");
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/frontcontroller2.phar.phpt b/ext/phar/tests/zip/frontcontroller2.phar.phpt
new file mode 100644
index 0000000000..ac64424ecb
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller2.phar.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Phar front controller PHP test zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller2.phar.php/a.php
+REQUEST_URI=/frontcontroller2.phar.php/a.php
+--FILE_EXTERNAL--
+frontcontroller.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECT--
+hio
diff --git a/ext/phar/tests/zip/frontcontroller2.phar.zip b/ext/phar/tests/zip/frontcontroller2.phar.zip
new file mode 100644
index 0000000000..7ef43dc000
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller2.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/frontcontroller20.phar.phpt b/ext/phar/tests/zip/frontcontroller20.phar.phpt
new file mode 100644
index 0000000000..4b5859b33d
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller20.phar.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller $_SERVER munging failure 3 zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller20.phar.php/
+REQUEST_URI=/frontcontroller20.phar.php/
+--FILE_EXTERNAL--
+frontcontroller11.phar.zip
+--EXPECTF--
+Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Non-string value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME' in %sfrontcontroller20.phar.php:2
+Stack trace:
+#0 %sfrontcontroller20.phar.php(2): Phar::mungServer(Array)
+#1 {main}
+ thrown in %sfrontcontroller20.phar.php on line 2
diff --git a/ext/phar/tests/zip/frontcontroller21.phar.phpt b/ext/phar/tests/zip/frontcontroller21.phar.phpt
new file mode 100644
index 0000000000..cd55d9c4c6
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller21.phar.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Phar front controller $_SERVER munging success zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller21.phar.php/index.php
+REQUEST_URI=/frontcontroller21.phar.php/index.php?test=hi
+--FILE_EXTERNAL--
+frontcontroller12.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECTF--
+string(10) "/index.php"
+string(%d) "phar://%sfrontcontroller21.phar.php/index.php"
+string(%d) "phar://%sfrontcontroller21.phar.php/index.php"
+string(18) "/index.php?test=hi"
+string(37) "/frontcontroller21.phar.php/index.php"
+string(37) "/frontcontroller21.phar.php/index.php"
+string(%d) "%s/frontcontroller21.phar.php"
+string(45) "/frontcontroller21.phar.php/index.php?test=hi" \ No newline at end of file
diff --git a/ext/phar/tests/zip/frontcontroller3.phar.inc b/ext/phar/tests/zip/frontcontroller3.phar.inc
new file mode 100644
index 0000000000..a622b81f48
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller3.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller3.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller3.phar.zip');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array(), array("/hi" => "a.phps"));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/frontcontroller3.phar.phpt b/ext/phar/tests/zip/frontcontroller3.phar.phpt
new file mode 100644
index 0000000000..c34f4de8de
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller3.phar.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller phps zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller3.phar.php/a.phps
+REQUEST_URI=/frontcontroller3.phar.php/a.phps
+--FILE_EXTERNAL--
+frontcontroller.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECT--
+<code><span style="color: #000000">
+<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
+</span>
+</code>
diff --git a/ext/phar/tests/zip/frontcontroller3.phar.zip b/ext/phar/tests/zip/frontcontroller3.phar.zip
new file mode 100644
index 0000000000..0ca3681e0b
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller3.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/frontcontroller4.phar.inc b/ext/phar/tests/zip/frontcontroller4.phar.inc
new file mode 100644
index 0000000000..62956ba2a2
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller4.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller4.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller4.phar.zip');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array(), array("/hi" => true));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/frontcontroller4.phar.phpt b/ext/phar/tests/zip/frontcontroller4.phar.phpt
new file mode 100644
index 0000000000..0a6e39e2c0
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller4.phar.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Phar front controller index.php relocate (no /) zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller4.phar.php
+REQUEST_URI=/frontcontroller4.phar.php
+--FILE_EXTERNAL--
+frontcontroller.phar.zip
+--EXPECTHEADERS--
+Status: 301 Moved Permanently
+Location: /frontcontroller4.phar.php/index.php
+--EXPECT--
diff --git a/ext/phar/tests/zip/frontcontroller4.phar.zip b/ext/phar/tests/zip/frontcontroller4.phar.zip
new file mode 100644
index 0000000000..08208a5565
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller4.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/frontcontroller5.phar.inc b/ext/phar/tests/zip/frontcontroller5.phar.inc
new file mode 100644
index 0000000000..931fa975e1
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller5.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller5.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller5.phar.zip');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array(0 => "oops"));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/frontcontroller5.phar.phpt b/ext/phar/tests/zip/frontcontroller5.phar.phpt
new file mode 100644
index 0000000000..1e69240a0a
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller5.phar.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Phar front controller index.php relocate zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller5.phar.php/
+REQUEST_URI=/frontcontroller5.phar.php/
+--FILE_EXTERNAL--
+frontcontroller.phar.zip
+--EXPECTHEADERS--
+Status: 301 Moved Permanently
+Location: /frontcontroller5.phar.php/index.php
+--EXPECT--
diff --git a/ext/phar/tests/zip/frontcontroller5.phar.zip b/ext/phar/tests/zip/frontcontroller5.phar.zip
new file mode 100644
index 0000000000..0ab0472101
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller5.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/frontcontroller6.phar.inc b/ext/phar/tests/zip/frontcontroller6.phar.inc
new file mode 100644
index 0000000000..3b551f268d
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller6.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller6.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller6.phar.zip');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array("blah" => 100));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/frontcontroller6.phar.phpt b/ext/phar/tests/zip/frontcontroller6.phar.phpt
new file mode 100644
index 0000000000..4f3435be22
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller6.phar.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Phar front controller 404 zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller6.phar.php/notfound.php
+REQUEST_URI=/frontcontroller6.phar.php/notfound.php
+--FILE_EXTERNAL--
+frontcontroller.phar.zip
+--EXPECTHEADERS--
+Status: 404 Not Found
+--EXPECT--
+<html>
+ <head>
+ <title>File Not Found<title>
+ </head>
+ <body>
+ <h1>404 - File /notfound.php Not Found</h1>
+ </body>
+</html> \ No newline at end of file
diff --git a/ext/phar/tests/zip/frontcontroller6.phar.zip b/ext/phar/tests/zip/frontcontroller6.phar.zip
new file mode 100644
index 0000000000..bf98255fe9
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller6.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/frontcontroller7.phar.inc b/ext/phar/tests/zip/frontcontroller7.phar.inc
new file mode 100644
index 0000000000..42c10bc739
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller7.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller7.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller7.phar.zip');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array("blah" => null));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/frontcontroller7.phar.phpt b/ext/phar/tests/zip/frontcontroller7.phar.phpt
new file mode 100644
index 0000000000..2ce206fc21
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller7.phar.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Phar front controller alternate index file zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller7.phar.php/
+REQUEST_URI=/frontcontroller7.phar.php/
+--FILE_EXTERNAL--
+frontcontroller2.phar.zip
+--EXPECTHEADERS--
+Status: 301 Moved Permanently
+Location: /frontcontroller7.phar.php/a.php
+--EXPECT--
diff --git a/ext/phar/tests/zip/frontcontroller7.phar.zip b/ext/phar/tests/zip/frontcontroller7.phar.zip
new file mode 100644
index 0000000000..02fc3e27b6
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller7.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/frontcontroller8.phar.inc b/ext/phar/tests/zip/frontcontroller8.phar.inc
new file mode 100644
index 0000000000..e04ac414e9
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller8.phar.inc
@@ -0,0 +1,13 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller8.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller8.phar.zip');
+$a['a.phps'] = 'hio1';
+$a['a.jpg'] = 'hio2';
+$a['a.php'] = '<?php function hio(){}';
+$a['fronk.gronk'] = 'hio3';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array("jpg" => "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/frontcontroller8.phar.phpt b/ext/phar/tests/zip/frontcontroller8.phar.phpt
new file mode 100644
index 0000000000..dd806b6cf0
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller8.phar.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Phar front controller no index file 404 zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller8.phar.php/
+REQUEST_URI=/frontcontroller8.phar.php/
+--FILE_EXTERNAL--
+frontcontroller3.phar.zip
+--EXPECTHEADERS--
+Status: 404 Not Found
+--EXPECT--
+<html>
+ <head>
+ <title>File Not Found<title>
+ </head>
+ <body>
+ <h1>404 - File index.php Not Found</h1>
+ </body>
+</html> \ No newline at end of file
diff --git a/ext/phar/tests/zip/frontcontroller8.phar.zip b/ext/phar/tests/zip/frontcontroller8.phar.zip
new file mode 100644
index 0000000000..41952ce745
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller8.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/frontcontroller9.phar.inc b/ext/phar/tests/zip/frontcontroller9.phar.inc
new file mode 100644
index 0000000000..50440451f7
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller9.phar.inc
@@ -0,0 +1,14 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller9.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller9.phar.zip');
+$a['a.phps'] = 'hio1';
+$a['a.jpg'] = 'hio2';
+$a['a.php'] = '<?php function hio(){}';
+$a['fronk.gronk'] = 'hio3';
+$a->setStub('<?php
+Phar::mungServer(array());
+Phar::webPhar("whatever", "index.php", null, array("jpg" => "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/frontcontroller9.phar.phpt b/ext/phar/tests/zip/frontcontroller9.phar.phpt
new file mode 100644
index 0000000000..70dbaa05ad
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller9.phar.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller rewrite array zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller9.phar.php/hi
+REQUEST_URI=/frontcontroller9.phar.php/hi
+--FILE_EXTERNAL--
+frontcontroller3.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECT--
+<code><span style="color: #000000">
+<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
+</span>
+</code> \ No newline at end of file
diff --git a/ext/phar/tests/zip/frontcontroller9.phar.zip b/ext/phar/tests/zip/frontcontroller9.phar.zip
new file mode 100644
index 0000000000..d3f4ff8404
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller9.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/make_invalid_tar.php.inc b/ext/phar/tests/zip/make_invalid_tar.php.inc
new file mode 100644
index 0000000000..cec8ef7793
--- /dev/null
+++ b/ext/phar/tests/zip/make_invalid_tar.php.inc
@@ -0,0 +1,12 @@
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+class corrupter extends tarmaker {
+function close()
+{
+ parent::close();
+ $fp = fopen($this->path, 'r+b');
+ fseek($fp, 20);
+ fwrite($fp, 'oopsie');
+ fclose($fp);
+}
+} \ No newline at end of file
diff --git a/ext/phar/tests/zip/open_for_write_existing.phpt b/ext/phar/tests/zip/open_for_write_existing.phpt
new file mode 100644
index 0000000000..6e677e7451
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_existing.phpt
@@ -0,0 +1,38 @@
+--TEST--
+Phar: fopen a .phar for writing (existing file) zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = 'phar://' . $fname;
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>");
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+foreach ($files as $n => $file) {
+$a->addFile($n, $file);
+}
+$a->close();
+
+$fp = fopen($pname . '/b/c.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include $pname . '/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+--EXPECT--
+extra
+===DONE===
diff --git a/ext/phar/tests/zip/open_for_write_existing_b.phpt b/ext/phar/tests/zip/open_for_write_existing_b.phpt
new file mode 100755
index 0000000000..e3eb75ccc4
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_existing_b.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Phar: fopen a .phar for writing (existing file) zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = 'phar://' . $fname;
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>");
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+foreach ($files as $n => $file) {
+$a->addFile($n, $file);
+}
+$a->close();
+
+function err_handler($errno, $errstr, $errfile, $errline) {
+ echo "Catchable fatal error: $errstr in $errfile on line $errline\n";
+}
+
+set_error_handler("err_handler", E_RECOVERABLE_ERROR);
+
+$fp = fopen($pname . '/b/c.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include $pname . '/b/c.php';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_existing_b.phar.zip.php/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_b.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %spen_for_write_existing_b.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %spen_for_write_existing_b.php on line %d
+This is b/c
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/zip/open_for_write_existing_c.phpt b/ext/phar/tests/zip/open_for_write_existing_c.phpt
new file mode 100755
index 0000000000..308c74d348
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_existing_c.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Phar: fopen a .phar for writing (existing file) tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = 'phar://' . $fname;
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>");
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+foreach ($files as $n => $file) {
+$a->addFile($n, $file);
+}
+$a->close();
+
+$fp = fopen($pname . '/b/c.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include $pname . '/b/c.php';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_existing_c.phar.zip.php/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_c.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c.php on line %d
+This is b/c
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/zip/open_for_write_newfile.phpt b/ext/phar/tests/zip/open_for_write_newfile.phpt
new file mode 100644
index 0000000000..e30ae54636
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_newfile.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Phar: fopen a .phar for writing (new file) zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = 'phar://' . $fname;
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>");
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+foreach ($files as $n => $file) {
+$a->addFile($n, $file);
+}
+$a->close();
+
+$fp = fopen($pname . '/b/new.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include $pname . '/b/c.php';
+include $pname . '/b/new.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+--EXPECT--
+This is b/c
+extra
+===DONE===
diff --git a/ext/phar/tests/zip/open_for_write_newfile_b.phpt b/ext/phar/tests/zip/open_for_write_newfile_b.phpt
new file mode 100755
index 0000000000..854917eb4b
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_newfile_b.phpt
@@ -0,0 +1,56 @@
+--TEST--
+Phar: fopen a .phar for writing (new file) zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = 'phar://' . $fname;
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>");
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+foreach ($files as $n => $file) {
+$a->addFile($n, $file);
+}
+$a->close();
+
+function err_handler($errno, $errstr, $errfile, $errline) {
+ echo "Catchable fatal error: $errstr in $errfile on line $errline\n";
+}
+
+set_error_handler("err_handler", E_RECOVERABLE_ERROR);
+
+$fp = fopen($pname . '/b/new.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include $pname . '/b/c.php';
+include $pname . '/b/new.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_newfile_b.phar.zip.php/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_b.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line %d
+This is b/c
+
+Warning: include(phar://%sopen_for_write_newfile_b.phar.zip.php/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_b.phar.zip.php" in %sopen_for_write_newfile_b.php on line %d
+
+Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_b.phar.zip.php/b/new.php' for inclusion (include_path='%s') in %sopen_for_write_newfile_b.php on line %d
+
+===DONE===
diff --git a/ext/phar/tests/zip/open_for_write_newfile_c.phpt b/ext/phar/tests/zip/open_for_write_newfile_c.phpt
new file mode 100755
index 0000000000..01b5871511
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_newfile_c.phpt
@@ -0,0 +1,50 @@
+--TEST--
+Phar: fopen a .phar for writing (new file) zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = 'phar://' . $fname;
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>");
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+foreach ($files as $n => $file) {
+$a->addFile($n, $file);
+}
+$a->close();
+
+$fp = fopen($pname . '/b/new.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include $pname . '/b/c.php';
+include $pname . '/b/new.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_newfile_c.phar.zip.php/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_c.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c.php on line %d
+This is b/c
+
+Warning: include(phar://%sopen_for_write_newfile_c.phar.zip.php/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_c.phar.zip.php" in %sopen_for_write_newfile_c.php on line %d
+
+Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_c.phar.zip.php/b/new.php' for inclusion (include_path='%s') in %sopen_for_write_newfile_c.php on line %d
+
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/zip/phar_begin_setstub_commit.phpt b/ext/phar/tests/zip/phar_begin_setstub_commit.phpt
new file mode 100755
index 0000000000..66c0134634
--- /dev/null
+++ b/ext/phar/tests/zip/phar_begin_setstub_commit.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Phar::startBuffering()/setStub()/stopBuffering() zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar.zip', 0, 'brandnewphar.phar');
+var_dump($p->isZip());
+//var_dump($p->getStub());
+var_dump($p->isBuffering());
+$p->startBuffering();
+var_dump($p->isBuffering());
+$p['a.php'] = '<?php var_dump("Hello");';
+$p->setStub('<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
+include 'phar://brandnewphar.phar/a.php';
+var_dump($p->getStub());
+$p['b.php'] = '<?php var_dump("World");';
+$p->setStub('<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER();');
+include 'phar://brandnewphar.phar/b.php';
+var_dump($p->getStub());
+$p->stopBuffering();
+echo "===COMMIT===\n";
+var_dump($p->isBuffering());
+include 'phar://brandnewphar.phar/a.php';
+include 'phar://brandnewphar.phar/b.php';
+var_dump($p->getStub());
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/brandnewphar.phar.zip');
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
+string(5) "Hello"
+string(84) "<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
+"
+string(5) "World"
+string(85) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
+"
+===COMMIT===
+bool(true)
+string(5) "Hello"
+string(5) "World"
+string(85) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
+"
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/zip/phar_buildfromiterator4.phpt b/ext/phar/tests/zip/phar_buildfromiterator4.phpt
new file mode 100644
index 0000000000..fe402b6b45
--- /dev/null
+++ b/ext/phar/tests/zip/phar_buildfromiterator4.phpt
@@ -0,0 +1,66 @@
+--TEST--
+Phar::buildFromIterator() iterator, 1 file passed in zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+class myIterator implements Iterator
+{
+ var $a;
+ function __construct(array $a)
+ {
+ $this->a = $a;
+ }
+ function next() {
+ echo "next\n";
+ return next($this->a);
+ }
+ function current() {
+ echo "current\n";
+ return current($this->a);
+ }
+ function key() {
+ echo "key\n";
+ return key($this->a);
+ }
+ function valid() {
+ echo "valid\n";
+ return current($this->a);
+ }
+ function rewind() {
+ echo "rewind\n";
+ return reset($this->a);
+ }
+}
+try {
+ chdir(dirname(__FILE__));
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+ var_dump($phar->buildFromIterator(new myIterator(array('a' => basename(__FILE__, 'php') . 'phpt'))));
+ var_dump($phar->isZip());
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+rewind
+valid
+current
+key
+next
+valid
+array(1) {
+ ["a"]=>
+ string(%d) "%sphar_buildfromiterator4.phpt"
+}
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/zip/phar_buildfromiterator5.phpt b/ext/phar/tests/zip/phar_buildfromiterator5.phpt
new file mode 100644
index 0000000000..450ada100d
--- /dev/null
+++ b/ext/phar/tests/zip/phar_buildfromiterator5.phpt
@@ -0,0 +1,59 @@
+--TEST--
+Phar::buildFromIterator() iterator, iterator returns non-string zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+class myIterator implements Iterator
+{
+ var $a;
+ function __construct(array $a)
+ {
+ $this->a = $a;
+ }
+ function next() {
+ echo "next\n";
+ return next($this->a);
+ }
+ function current() {
+ echo "current\n";
+ return current($this->a);
+ }
+ function key() {
+ echo "key\n";
+ return key($this->a);
+ }
+ function valid() {
+ echo "valid\n";
+ return current($this->a);
+ }
+ function rewind() {
+ echo "rewind\n";
+ return reset($this->a);
+ }
+}
+try {
+ chdir(dirname(__FILE__));
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+ var_dump($phar->buildFromIterator(new myIterator(array('a' => new stdClass))));
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+rewind
+valid
+current
+string(24) "UnexpectedValueException"
+Iterator myIterator returned an invalid value (must return a string)
+===DONE===
diff --git a/ext/phar/tests/zip/phar_buildfromiterator6.phpt b/ext/phar/tests/zip/phar_buildfromiterator6.phpt
new file mode 100644
index 0000000000..2dfb04dbf0
--- /dev/null
+++ b/ext/phar/tests/zip/phar_buildfromiterator6.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Phar::buildFromIterator() iterator, key is int zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+class myIterator implements Iterator
+{
+ var $a;
+ function __construct(array $a)
+ {
+ $this->a = $a;
+ }
+ function next() {
+ echo "next\n";
+ return next($this->a);
+ }
+ function current() {
+ echo "current\n";
+ return current($this->a);
+ }
+ function key() {
+ echo "key\n";
+ return key($this->a);
+ }
+ function valid() {
+ echo "valid\n";
+ return current($this->a);
+ }
+ function rewind() {
+ echo "rewind\n";
+ return reset($this->a);
+ }
+}
+try {
+ chdir(dirname(__FILE__));
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+ var_dump($phar->buildFromIterator(new myIterator(array(basename(__FILE__, 'php') . 'phpt'))));
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+rewind
+valid
+current
+key
+string(24) "UnexpectedValueException"
+Iterator myIterator returned an invalid key (must return a string)
+===DONE===
diff --git a/ext/phar/tests/zip/phar_buildfromiterator7.phpt b/ext/phar/tests/zip/phar_buildfromiterator7.phpt
new file mode 100644
index 0000000000..16ba6d61b9
--- /dev/null
+++ b/ext/phar/tests/zip/phar_buildfromiterator7.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Phar::buildFromIterator() iterator, file can't be opened zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+class myIterator implements Iterator
+{
+ var $a;
+ function __construct(array $a)
+ {
+ $this->a = $a;
+ }
+ function next() {
+ echo "next\n";
+ return next($this->a);
+ }
+ function current() {
+ echo "current\n";
+ return current($this->a);
+ }
+ function key() {
+ echo "key\n";
+ return key($this->a);
+ }
+ function valid() {
+ echo "valid\n";
+ return current($this->a);
+ }
+ function rewind() {
+ echo "rewind\n";
+ return reset($this->a);
+ }
+}
+try {
+ chdir(dirname(__FILE__));
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+ var_dump($phar->buildFromIterator(new myIterator(array('a' => basename(__FILE__, 'php') . '/oopsie/there.phpt'))));
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECT--
+rewind
+valid
+current
+key
+string(24) "UnexpectedValueException"
+Iterator myIterator returned a file that could not be opened "phar_buildfromiterator7./oopsie/there.phpt"
+===DONE===
diff --git a/ext/phar/tests/zip/phar_buildfromiterator8.phpt b/ext/phar/tests/zip/phar_buildfromiterator8.phpt
new file mode 100644
index 0000000000..0222dc8b4f
--- /dev/null
+++ b/ext/phar/tests/zip/phar_buildfromiterator8.phpt
@@ -0,0 +1,73 @@
+--TEST--
+Phar::buildFromIterator() iterator, SplFileInfo as current zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+try {
+ chdir(dirname(__FILE__));
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+ $a = $phar->buildFromIterator(new RegexIterator(new DirectoryIterator('.'), '/^frontcontroller\d{0,2}\.phar\.phpt\\z|^\.\\z|^\.\.\\z/'), dirname(__FILE__) . DIRECTORY_SEPARATOR);
+ asort($a);
+ var_dump($a);
+ var_dump($phar->isZip());
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+array(21) {
+ ["frontcontroller1.phar.phpt"]=>
+ string(%d) "%sfrontcontroller1.phar.phpt"
+ ["frontcontroller10.phar.phpt"]=>
+ string(%d) "%sfrontcontroller10.phar.phpt"
+ ["frontcontroller11.phar.phpt"]=>
+ string(%d) "%sfrontcontroller11.phar.phpt"
+ ["frontcontroller12.phar.phpt"]=>
+ string(%d) "%sfrontcontroller12.phar.phpt"
+ ["frontcontroller13.phar.phpt"]=>
+ string(%d) "%sfrontcontroller13.phar.phpt"
+ ["frontcontroller14.phar.phpt"]=>
+ string(%d) "%sfrontcontroller14.phar.phpt"
+ ["frontcontroller15.phar.phpt"]=>
+ string(%d) "%sfrontcontroller15.phar.phpt"
+ ["frontcontroller16.phar.phpt"]=>
+ string(%d) "%sfrontcontroller16.phar.phpt"
+ ["frontcontroller17.phar.phpt"]=>
+ string(%d) "%sfrontcontroller17.phar.phpt"
+ ["frontcontroller18.phar.phpt"]=>
+ string(%d) "%sfrontcontroller18.phar.phpt"
+ ["frontcontroller19.phar.phpt"]=>
+ string(%d) "%sfrontcontroller19.phar.phpt"
+ ["frontcontroller2.phar.phpt"]=>
+ string(%d) "%sfrontcontroller2.phar.phpt"
+ ["frontcontroller20.phar.phpt"]=>
+ string(%d) "%sfrontcontroller20.phar.phpt"
+ ["frontcontroller21.phar.phpt"]=>
+ string(%d) "%sfrontcontroller21.phar.phpt"
+ ["frontcontroller3.phar.phpt"]=>
+ string(%d) "%sfrontcontroller3.phar.phpt"
+ ["frontcontroller4.phar.phpt"]=>
+ string(%d) "%sfrontcontroller4.phar.phpt"
+ ["frontcontroller5.phar.phpt"]=>
+ string(%d) "%sfrontcontroller5.phar.phpt"
+ ["frontcontroller6.phar.phpt"]=>
+ string(%d) "%sfrontcontroller6.phar.phpt"
+ ["frontcontroller7.phar.phpt"]=>
+ string(%d) "%sfrontcontroller7.phar.phpt"
+ ["frontcontroller8.phar.phpt"]=>
+ string(%d) "%sfrontcontroller8.phar.phpt"
+ ["frontcontroller9.phar.phpt"]=>
+ string(%d) "%sfrontcontroller9.phar.phpt"
+}
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/zip/phar_buildfromiterator9.phpt b/ext/phar/tests/zip/phar_buildfromiterator9.phpt
new file mode 100644
index 0000000000..0b56307545
--- /dev/null
+++ b/ext/phar/tests/zip/phar_buildfromiterator9.phpt
@@ -0,0 +1,65 @@
+--TEST--
+Phar::buildFromIterator() iterator, 1 file resource passed in
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+class myIterator implements Iterator
+{
+ var $a;
+ function __construct(array $a)
+ {
+ $this->a = $a;
+ }
+ function next() {
+ echo "next\n";
+ return next($this->a);
+ }
+ function current() {
+ echo "current\n";
+ return current($this->a);
+ }
+ function key() {
+ echo "key\n";
+ return key($this->a);
+ }
+ function valid() {
+ echo "valid\n";
+ return current($this->a);
+ }
+ function rewind() {
+ echo "rewind\n";
+ return reset($this->a);
+ }
+}
+try {
+ chdir(dirname(__FILE__));
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar');
+ var_dump($phar->buildFromIterator(new myIterator(array('a' => $a = fopen(basename(__FILE__, 'php') . 'phpt', 'r')))));
+ fclose($a);
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+rewind
+valid
+current
+key
+next
+valid
+array(1) {
+ ["a"]=>
+ string(%d) "[stream]"
+}
+===DONE===
diff --git a/ext/phar/tests/zip/phar_commitwrite.phpt b/ext/phar/tests/zip/phar_commitwrite.phpt
new file mode 100644
index 0000000000..b954e60069
--- /dev/null
+++ b/ext/phar/tests/zip/phar_commitwrite.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Phar::setStub()/stopBuffering() tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar.zip', 0, 'brandnewphar.phar');
+$p['file1.txt'] = 'hi';
+$p->stopBuffering();
+var_dump($p->getStub());
+$p->setStub("<?php
+function __autoload(\$class)
+{
+ include 'phar://' . str_replace('_', '/', \$class);
+}
+Phar::mapPhar('brandnewphar.phar');
+include 'phar://brandnewphar.phar/startup.php';
+__HALT_COMPILER();
+?>");
+var_dump($p->getStub());
+var_dump($p->isZip());
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/brandnewphar.phar.zip');
+?>
+--EXPECT--
+string(60) "<?php // zip-based phar archive stub file
+__HALT_COMPILER();"
+string(200) "<?php
+function __autoload($class)
+{
+ include 'phar://' . str_replace('_', '/', $class);
+}
+Phar::mapPhar('brandnewphar.phar');
+include 'phar://brandnewphar.phar/startup.php';
+__HALT_COMPILER(); ?>
+"
+bool(true)
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/zip/phar_copy.phpt b/ext/phar/tests/zip/phar_copy.phpt
new file mode 100644
index 0000000000..d5a234fdc5
--- /dev/null
+++ b/ext/phar/tests/zip/phar_copy.phpt
@@ -0,0 +1,56 @@
+--TEST--
+Phar: copy() zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=1
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar.php';
+
+$pname = 'phar://'.$fname;
+$iname = '/file.txt';
+$ename = '/error/';
+
+$p = new Phar($fname);
+
+try
+{
+ $p['a'] = 'hi';
+ $p->startBuffering();
+ $p->copy('a', 'b');
+ echo file_get_contents($p['b']->getPathName());
+ $p->copy('b', 'c');
+ $p->stopBuffering();
+ echo file_get_contents($p['c']->getPathName());
+ copy($fname, $fname2);
+ var_dump($p->isZip());
+ $p->copy('a', $ename);
+}
+catch(Exception $e)
+{
+ echo $e->getMessage() . "\n";
+}
+ini_set('phar.readonly',1);
+$p2 = new Phar($fname2);
+var_dump($p2->isZip());
+echo "\n";
+echo 'a: ' , file_get_contents($p2['a']->getPathName());
+echo 'b: ' ,file_get_contents($p2['b']->getPathName());
+echo 'c: ' ,file_get_contents($p2['c']->getPathName());
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.php'); ?>
+--EXPECTF--
+hihibool(true)
+file "/error/" contains invalid characters empty directory, cannot be copied from "a" in phar %s
+bool(true)
+
+a: hib: hic: hi===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/zip/phar_magic.phpt b/ext/phar/tests/zip/phar_magic.phpt
new file mode 100644
index 0000000000..7afcc3a56c
--- /dev/null
+++ b/ext/phar/tests/zip/phar_magic.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Phar: include/fopen magic zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$p = new Phar($fname);
+var_dump($p->isZip());
+$p['a'] = '<?php include "b/c.php";' . "\n";
+$p['b/c.php'] = '<?php echo "in b\n";$a = fopen("a", "r", true);echo stream_get_contents($a);fclose($a);include dirname(__FILE__) . "/../d";';
+$p['d'] = "in d\n";
+$p->setStub('<?php
+include "phar://" . __FILE__ . "/a";
+__HALT_COMPILER();');
+include $fname;
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+bool(true)
+in b
+<?php include "b/c.php";
+in d
+===DONE===
diff --git a/ext/phar/tests/zip/phar_setalias.phpt b/ext/phar/tests/zip/phar_setalias.phpt
new file mode 100644
index 0000000000..ecd969a1dd
--- /dev/null
+++ b/ext/phar/tests/zip/phar_setalias.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Phar::setAlias() zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('.phar/stub.php', '<?php echo "first stub\n"; __HALT_COMPILER(); ?>');
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+$files['.phar/alias.txt'] = 'hio';
+foreach ($files as $n => $file) {
+$a->addFile($n, $file);
+}
+$a->close();
+
+$phar = new Phar($fname);
+echo $phar->getAlias() . "\n";
+$phar->setAlias('test');
+echo $phar->getAlias() . "\n";
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php');
+__HALT_COMPILER();
+?>
+--EXPECT--
+hio
+test
+===DONE===
diff --git a/ext/phar/tests/zip/phar_setalias2.phpt b/ext/phar/tests/zip/phar_setalias2.phpt
new file mode 100644
index 0000000000..0fc6430fd5
--- /dev/null
+++ b/ext/phar/tests/zip/phar_setalias2.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Phar::setAlias() error zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('.phar/stub.php', '<?php echo "first stub\n"; __HALT_COMPILER(); ?>');
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+$files['.phar/alias.txt'] = 'hio';
+foreach ($files as $n => $file) {
+$a->addFile($n, $file);
+}
+$a->close();
+
+$phar = new Phar($fname);
+echo $phar->getAlias() . "\n";
+$phar->setAlias('test');
+echo $phar->getAlias() . "\n";
+$phar = new Phar(dirname(__FILE__) . '/notphar.phar');
+try {
+ $phar->setAlias('test');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+unlink(dirname(__FILE__) . '/notphar.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+hio
+test
+alias "test" is already used for archive "%sphar_setalias2.phar.php" and cannot be used for other archives
+===DONE===
diff --git a/ext/phar/tests/zip/phar_stub_error.phpt b/ext/phar/tests/zip/phar_stub_error.phpt
new file mode 100755
index 0000000000..6a1d3fc199
--- /dev/null
+++ b/ext/phar/tests/zip/phar_stub_error.phpt
@@ -0,0 +1,62 @@
+--TEST--
+Phar::setStub()/getStub() zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('.phar/stub.php', $stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>');
+
+$files = array();
+$files['a'] = 'a';
+$files['.phar/alias.txt'] = 'hio';
+foreach ($files as $n => $file) {
+$a->addFile($n, $file);
+}
+$a->close();
+
+$phar = new Phar($fname);
+var_dump($stub);
+var_dump($phar->getStub());
+var_dump($phar->getStub() == $stub);
+
+$newstub = '<?php echo "second stub\n"; _x_HALT_COMPILER(); ?>';
+try
+{
+ $phar->setStub($newstub);
+}
+catch(exception $e)
+{
+ echo 'Exception: ' . $e->getMessage() . "\n";
+}
+var_dump($phar->getStub());
+var_dump($phar->getStub() == $stub);
+$phar->stopBuffering();
+var_dump($phar->getStub());
+var_dump($phar->getStub() == $stub);
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+bool(true)
+Exception: illegal stub for zip-based phar "%sphar_stub_error.phar.php"
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+bool(true)
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/zip/refcount1.phpt b/ext/phar/tests/zip/refcount1.phpt
new file mode 100644
index 0000000000..b70fb5e146
--- /dev/null
+++ b/ext/phar/tests/zip/refcount1.phpt
@@ -0,0 +1,71 @@
+--TEST--
+Phar: test that refcounting avoids problems with deleting a file zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+<?php if (version_compare(PHP_VERSION, "5.3", "<")) die("skip requires 5.3 or later"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>");
+
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+$files['.phar/alias.txt'] = 'hio';
+foreach ($files as $n => $file) {
+$a->addFile($n, $file);
+}
+$a->close();
+
+$fp = fopen($pname . '/b/c.php', 'wb');
+fwrite($fp, "extra");
+fclose($fp);
+echo "===CLOSE===\n";
+$p = new Phar($fname);
+$b = fopen($pname . '/b/c.php', 'rb');
+$a = $p['b/c.php'];
+var_dump($a);
+var_dump(fread($b, 20));
+rewind($b);
+echo "===UNLINK===\n";
+unlink($pname . '/b/c.php');
+var_dump($a);
+var_dump(fread($b, 20));
+include $pname . '/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+===CLOSE===
+object(PharFileInfo)#%d (2) {
+ ["pathName":"SplFileInfo":private]=>
+ string(%d) "phar://%srefcount1.phar.php/b"
+ ["fileName":"SplFileInfo":private]=>
+ string(%d) "phar://%srefcount1.phar.php/b/c.php"
+}
+string(5) "extra"
+===UNLINK===
+
+Warning: unlink(): phar error: "b/c.php" in phar "%srefcount1.phar.php", has open file pointers, cannot unlink in %srefcount1.php on line %d
+object(PharFileInfo)#%d (2) {
+ ["pathName":"SplFileInfo":private]=>
+ string(%d) "phar://%srefcount1.phar.php/b"
+ ["fileName":"SplFileInfo":private]=>
+ string(%s) "phar://%srefcount1.phar.php/b/c.php"
+}
+string(5) "extra"
+extra
+===DONE===
diff --git a/ext/phar/tests/zip/refcount1_5_2.phpt b/ext/phar/tests/zip/refcount1_5_2.phpt
new file mode 100755
index 0000000000..5098ccd90e
--- /dev/null
+++ b/ext/phar/tests/zip/refcount1_5_2.phpt
@@ -0,0 +1,63 @@
+--TEST--
+Phar: test that refcounting avoids problems with deleting a file zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+<?php if (version_compare(PHP_VERSION, "5.2", ">")) die("skip requires 5.2 or earlier"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>");
+
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+$files['.phar/alias.txt'] = 'hio';
+foreach ($files as $n => $file) {
+$a->addFile($n, $file);
+}
+$a->close();
+
+$fp = fopen($pname . '/b/c.php', 'wb');
+fwrite($fp, "extra");
+fclose($fp);
+echo "===CLOSE===\n";
+$p = new Phar($fname);
+$b = fopen($pname . '/b/c.php', 'rb');
+$a = $p['b/c.php'];
+var_dump($a);
+var_dump(fread($b, 20));
+rewind($b);
+echo "===UNLINK===\n";
+unlink($pname . '/b/c.php');
+var_dump($a);
+var_dump(fread($b, 20));
+include $pname . '/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+===CLOSE===
+object(PharFileInfo)#%d (0) {
+}
+string(5) "extra"
+===UNLINK===
+
+Warning: unlink(): phar error: "b/c.php" in phar "%sefcount1.phar.php", has open file pointers, cannot unlink in %sefcount1.php on line %d
+object(PharFileInfo)#%d (0) {
+}
+string(5) "extra"
+extra
+===DONE===
diff --git a/ext/phar/tests/zip/rename.phpt b/ext/phar/tests/zip/rename.phpt
new file mode 100644
index 0000000000..9a97f266ac
--- /dev/null
+++ b/ext/phar/tests/zip/rename.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Phar: rename test zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zip")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('.phar/stub.php', "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>");
+
+$files = array();
+$files['a'] = 'a';
+foreach ($files as $n => $file) {
+$a->addFile($n, $file);
+}
+$a->close();
+
+include $fname;
+
+echo file_get_contents($pname . '/a') . "\n";
+rename($pname . '/a', $pname . '/b');
+echo file_get_contents($pname . '/b') . "\n";
+echo file_get_contents($pname . '/a') . "\n";
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+a
+a
+
+Warning: file_get_contents(phar://%srename.phar.php/a): failed to open stream: phar error: "a" is not a file in phar "%srename.phar.php" in %srename.php on line %d \ No newline at end of file
diff --git a/ext/phar/tests/zip/tarmaker.php.inc b/ext/phar/tests/zip/tarmaker.php.inc
new file mode 100644
index 0000000000..ad05ae64c3
--- /dev/null
+++ b/ext/phar/tests/zip/tarmaker.php.inc
@@ -0,0 +1,70 @@
+<?php
+// stolen from PEAR2_Pyrus_Developer_Creator_Zip by Greg Beaver, the original author, for use in unit tests
+class tarmaker
+{
+ /**
+ * Path to archive file
+ *
+ * @var string
+ */
+ protected $archive;
+ /**
+ * @var ZIPArchive
+ */
+ protected $zip;
+ protected $path;
+ function __construct($path)
+ {
+ if (!class_exists('ZIPArchive')) {
+ throw new Exception(
+ 'Zip extension is not available');
+ }
+ $this->path = $path;
+ }
+
+ /**
+ * save a file inside this package
+ * @param string relative path within the package
+ * @param string|resource file contents or open file handle
+ */
+ function addFile($path, $fileOrStream)
+ {
+ if (is_resource($fileOrStream)) {
+ $this->zip->addFromString($path, stream_get_contents($fileOrStream));
+ } else {
+ $this->zip->addFromString($path, $fileOrStream);
+ }
+ }
+
+ /**
+ * Initialize the package creator
+ */
+ function init()
+ {
+ $this->zip = new ZipArchive;
+ if (true !== $this->zip->open($this->path, ZIPARCHIVE::CREATE)) {
+ throw new Exception(
+ 'Cannot open ZIP archive ' . $this->path
+ );
+ }
+ }
+
+ /**
+ * Create an internal directory, creating parent directories as needed
+ *
+ * This is a no-op for the tar creator
+ * @param string $dir
+ */
+ function mkdir($dir)
+ {
+ $this->zip->addEmptyDir($dir);
+ }
+
+ /**
+ * Finish saving the package
+ */
+ function close()
+ {
+ $this->zip->close();
+ }
+} \ No newline at end of file