summaryrefslogtreecommitdiff
path: root/ext/phar/tests/phar_test.inc
blob: 82987cb19dd2b315601f40e785622940ae764ec6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php

$manifest = '';
$glags = 0;

foreach($files as $name => $cont)
{
	global $gflags, $files;

	$comp = NULL;
	$crc32= NULL;
	$clen = NULL;
	$ulen = NULL;
	$time = isset($ftime) ? $ftime : @mktime(12, 0, 0, 3, 1, 2006);
	$flags= 0;
	$perm = 0x000001B6;
	$meta = array();

	// overwrite if array
	if (is_array($cont))
	{
		foreach(array('comp','crc32','clen','ulen','time','flags','perm','meta','cont') as $what)
		{
			if (isset($cont[$what]))
			{
				$$what = $cont[$what];
			}
		}
	}

	// create if not yet done
	if (empty($comp)) $comp = $cont;
	if (empty($ulen)) $ulen = strlen($cont);
	if (empty($clen)) $clen = strlen($comp);
	if (empty($crc32))$crc32= crc32($cont);

	// write manifest entry
	$manifest .= pack('V', strlen($name)) . $name;
	$manifest .= pack('VVVVV', $ulen, $time, $clen, $crc32, $flags|$perm);
	foreach($meta as $type => $data)
	{
		$manifest .= pack('Vv', $type, strlen($data)) . $data;
	}
	$manifest .= pack('V', 0);

	// globals
	$gflags |= $flags;
	$files[$name] = $comp;
}

$alias = 'hio';
$manifest = pack('VnVV', count($files), 0x0900, $glags, strlen($alias)) . $alias . $manifest;
$file .= pack('V', strlen($manifest)) . $manifest;

foreach($files as $cont)
{
	$file .= $cont;
}

file_put_contents($fname, $file);

?>