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