xref: /PHP-5.3/ext/phar/tests/files/phar_test.inc (revision 377ff97a)
1<?php
2
3if (function_exists('date_default_timezone_set')) {
4	date_default_timezone_set('UTC');
5}
6
7$manifest = (binary)'';
8$gflags = 0;
9
10foreach($files as $name => $cont)
11{
12	global $gflags, $files;
13
14	$comp = NULL;
15	$crc32= NULL;
16	$clen = NULL;
17	$ulen = NULL;
18	$time = isset($ftime) ? $ftime : @mktime(12, 0, 0, 3, 1, 2006);
19	$flags= 0;
20	$perm = 0x000001B6;
21	$meta = NULL;
22
23	// overwrite if array
24	if (is_array($cont))
25	{
26		foreach(array('comp','crc32','clen','ulen','time','flags','perm','meta','cont') as $what)
27		{
28			if (isset($cont[$what]))
29			{
30				$$what = $cont[$what];
31			}
32		}
33	}
34
35	// create if not yet done
36	if (empty($comp)) $comp = $cont;
37	if (empty($ulen)) $ulen = strlen($cont);
38	if (empty($clen)) $clen = strlen($comp);
39	if (empty($crc32))$crc32= crc32((binary)$cont);
40	if (isset($meta)) $meta = serialize($meta);
41
42	// write manifest entry
43	$manifest .= pack('V', strlen($name)) . (binary)$name;
44	$manifest .= pack('VVVVVV', $ulen, $time, $clen, $crc32, $flags|$perm, strlen($meta)) . (binary)$meta;
45
46	// globals
47	$gflags |= $flags;
48	$files[$name] = $comp;
49}
50
51if (!isset($alias)) $alias = 'hio';
52
53if (isset($pmeta)) $pmeta = serialize($pmeta); else $pmeta = '';
54
55$manifest = pack('VnVV', count($files), isset($hasdir) ? 0x1110 : 0x1000, $gflags, strlen($alias)) . (binary)$alias . pack('V', strlen($pmeta)) . (binary)$pmeta . $manifest;
56$file = (binary)$file;
57$file .= pack('V', strlen($manifest)) . $manifest;
58
59foreach($files as $cont)
60{
61	$file .= (binary)$cont;
62}
63
64file_put_contents($fname, $file);
65
66if (@$gzip) {
67	$fp = gzopen($fname, 'w');
68	fwrite($fp, $file);
69	fclose($fp);
70}
71
72if (@$bz2) {
73	$fp = bzopen($fname, 'w');
74	fwrite($fp, $file);
75	fclose($fp);
76}
77
78?>