1--TEST--
2Phar with meta-data (write) zip-based
3--SKIPIF--
4<?php
5if (!extension_loaded("phar")) die("skip");
6if (version_compare(PHP_VERSION, "6.0", ">")) die("skip pre-unicode version of PHP required");
7?>
8--INI--
9phar.require_hash=0
10phar.readonly=0
11--FILE--
12<?php
13$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
14$f2name = dirname(__FILE__) . '/files/metadata.phar.zip';
15$pname = 'phar://' . $fname;
16$p2name = 'phar://' . $f2name;
17
18$file = "<?php __HALT_COMPILER(); ?>";
19
20$files = array();
21$files['a'] = array('cont' => 'a');
22$files['b'] = array('cont' => 'b', 'meta' => 'hi there');
23$files['c'] = array('cont' => 'c', 'meta' => array('hi', 'there'));
24$files['d'] = array('cont' => 'd', 'meta' => array('hi'=>'there','foo'=>'bar'));
25
26foreach($files as $name => $cont) {
27	var_dump(file_get_contents($p2name.'/'.$name));
28}
29
30copy($f2name, $fname);
31$phar = new Phar($fname);
32$phar->startBuffering();
33$phar['a']->setMetadata(42);
34$phar['b']->setMetadata(NULL);
35$phar['c']->setMetadata(array(25, 'foo'=>'bar'));
36$phar['d']->setMetadata(true);
37$phar->setMetadata('hi');
38
39foreach($files as $name => $cont) {
40	var_dump($phar[$name]->getMetadata());
41}
42$phar->stopBuffering();
43
44unset($phar);
45
46$phar = new Phar($fname);
47
48foreach($files as $name => $cont) {
49	var_dump(file_get_contents($pname.'/'.$name));
50}
51
52foreach($files as $name => $cont) {
53	var_dump($phar[$name]->getMetadata());
54}
55var_dump($phar->getMetadata());
56?>
57===DONE===
58--CLEAN--
59<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
60--EXPECT--
61string(1) "a"
62string(1) "b"
63string(1) "c"
64string(1) "d"
65int(42)
66NULL
67array(2) {
68  [0]=>
69  int(25)
70  ["foo"]=>
71  string(3) "bar"
72}
73bool(true)
74string(1) "a"
75string(1) "b"
76string(1) "c"
77string(1) "d"
78int(42)
79NULL
80array(2) {
81  [0]=>
82  int(25)
83  ["foo"]=>
84  string(3) "bar"
85}
86bool(true)
87string(2) "hi"
88===DONE===
89