2008-04-26 13:31:00 +08:00
--TEST--
Phar: Phar::extractTo()
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
--INI--
phar.readonly=0
--FILE--
<?php
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
$fname = dirname(__FILE__) . '/tempmanifest1.phar.php';
$pname = 'phar://' . $fname;
$a = new Phar($fname);
$a['file1.txt'] = 'hi';
$a['file2.txt'] = 'hi2';
$a['subdir/ectory/file.txt'] = 'hi3';
2008-05-08 10:58:45 +08:00
$a->mount($pname . '/mount', __FILE__);
2008-04-26 13:31:00 +08:00
$a->addEmptyDir('one/level');
2008-05-08 10:58:45 +08:00
$a->extractTo(dirname(__FILE__) . '/extract', 'mount');
2008-04-26 13:31:00 +08:00
$a->extractTo(dirname(__FILE__) . '/extract');
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
$out = array();
2008-08-01 21:36:19 +08:00
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/extract', 0x00003000), RecursiveIteratorIterator::CHILD_FIRST) as $p => $b) {
2008-04-26 13:31:00 +08:00
$out[] = $p;
}
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
sort($out);
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
foreach ($out as $b) {
2008-08-01 21:36:19 +08:00
echo "$b\n";
2008-04-26 13:31:00 +08:00
}
$a->extractTo(dirname(__FILE__) . '/extract1', 'file1.txt');
var_dump(file_get_contents(dirname(__FILE__) . '/extract1/file1.txt'));
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
$a->extractTo(dirname(__FILE__) . '/extract1', 'subdir/ectory/file.txt');
var_dump(file_get_contents(dirname(__FILE__) . '/extract1/subdir/ectory/file.txt'));
2013-09-18 16:52:51 +08:00
$a->extractTo(dirname(__FILE__) . '/extract1-2', array('file2.txt', 'one/level'));
var_dump(file_get_contents(dirname(__FILE__) . '/extract1-2/file2.txt'));
var_dump(is_dir(dirname(__FILE__) . '/extract1-2/one/level'));
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
try {
2008-08-01 21:36:19 +08:00
$a->extractTo(dirname(__FILE__) . '/whatever', 134);
2008-04-26 13:31:00 +08:00
} catch (Exception $e) {
2008-08-01 21:36:19 +08:00
echo $e->getMessage(), "\n";
2008-04-26 13:31:00 +08:00
}
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
$a->extractTo(array());
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
try {
2008-08-01 21:36:19 +08:00
$a->extractTo('');
2008-04-26 13:31:00 +08:00
} catch (Exception $e) {
2008-08-01 21:36:19 +08:00
echo $e->getMessage(), "\n";
2008-04-26 13:31:00 +08:00
}
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
file_put_contents(dirname(__FILE__) . '/oops', 'I is file');
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
try {
2008-08-01 21:36:19 +08:00
$a->extractTo(dirname(__FILE__) . '/oops', 'file1.txt');
2008-04-26 13:31:00 +08:00
} catch (Exception $e) {
2008-08-01 21:36:19 +08:00
echo $e->getMessage(), "\n";
2008-04-26 13:31:00 +08:00
}
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
try {
2008-08-01 21:36:19 +08:00
$a->extractTo(dirname(__FILE__) . '/oops1', array(array(), 'file1.txt'));
2008-04-26 13:31:00 +08:00
} catch (Exception $e) {
2008-08-01 21:36:19 +08:00
echo $e->getMessage(), "\n";
2008-04-26 13:31:00 +08:00
}
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
try {
2008-08-01 21:36:19 +08:00
$a->extractTo(dirname(__FILE__) . '/extract', 'file1.txt');
2008-04-26 13:31:00 +08:00
} catch (Exception $e) {
2008-08-01 21:36:19 +08:00
echo $e->getMessage(), "\n";
2008-04-26 13:31:00 +08:00
}
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
file_put_contents(dirname(__FILE__) . '/extract/file1.txt', 'first');
var_dump(file_get_contents(dirname(__FILE__) . '/extract/file1.txt'));
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
$a->extractTo(dirname(__FILE__) . '/extract', 'file1.txt', true);
var_dump(file_get_contents(dirname(__FILE__) . '/extract/file1.txt'));
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
try {
2008-08-01 21:36:19 +08:00
$a->extractTo(str_repeat('a', 20000), 'file1.txt');
2008-04-26 13:31:00 +08:00
} catch (Exception $e) {
2008-08-01 21:36:19 +08:00
echo $e->getMessage(), "\n";
2008-04-26 13:31:00 +08:00
}
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
$a[str_repeat('a', 20000)] = 'long';
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
try {
2008-08-01 21:36:19 +08:00
$a->extractTo(dirname(__FILE__) . '/extract', str_repeat('a', 20000));
2008-04-26 13:31:00 +08:00
} catch (Exception $e) {
2008-08-01 21:36:19 +08:00
echo $e->getMessage(), "\n";
2008-04-26 13:31:00 +08:00
}
2008-08-01 21:36:19 +08:00
2008-04-26 13:31:00 +08:00
?>
===DONE===
--CLEAN--
<?php
2008-04-27 15:04:56 +08:00
@rmdir(dirname(__FILE__) . '/whatever');
2008-04-26 13:31:00 +08:00
@unlink(dirname(__FILE__) . '/oops');
2008-04-27 00:57:14 +08:00
@rmdir(dirname(__FILE__) . '/oops1');
2008-04-26 13:31:00 +08:00
@unlink(dirname(__FILE__) . '/tempmanifest1.phar.php');
$e = dirname(__FILE__) . '/extract/';
@unlink($e . 'file1.txt');
@unlink($e . 'file2.txt');
@unlink($e . 'subdir/ectory/file.txt');
@rmdir($e . 'subdir/ectory');
@rmdir($e . 'subdir');
@rmdir($e . 'one/level');
@rmdir($e . 'one');
@rmdir($e);
2008-04-27 00:57:14 +08:00
$e = dirname(__FILE__) . '/extract1/';
2008-04-26 13:31:00 +08:00
@unlink($e . 'file1.txt');
@unlink($e . 'subdir/ectory/file.txt');
2008-04-27 00:57:14 +08:00
@rmdir($e . 'subdir/ectory');
@rmdir($e . 'subdir');
@rmdir($e);
2013-09-18 16:52:51 +08:00
$e = dirname(__FILE__) . '/extract1-2/';
2008-04-26 13:31:00 +08:00
@unlink($e . 'file2.txt');
@rmdir($e . 'one/level');
@rmdir($e . 'one');
@rmdir($e);
?>
--EXPECTF--
2008-04-27 19:31:27 +08:00
%sextract%cfile1.txt
2008-04-26 13:31:00 +08:00
%sextract%cfile2.txt
%sextract%cone
%sextract%csubdir
%sextract%csubdir%cectory
%sextract%csubdir%cectory%cfile.txt
string(2) "hi"
string(3) "hi3"
string(3) "hi2"
bool(false)
Invalid argument, expected a filename (string) or array of filenames
2008-08-01 21:36:19 +08:00
Warning: Phar::extractTo() expects parameter 1 to be %string, array given in %sphar_extract.php on line %d
2008-04-26 13:31:00 +08:00
Invalid argument, extraction path must be non-zero length
Unable to use path "%soops" for extraction, it is a file, must be a directory
Invalid argument, array of filenames to extract contains non-string value
Extraction from phar "%stempmanifest1.phar.php" failed: Cannot extract "file1.txt" to "%sextract/file1.txt", path already exists
string(5) "first"
string(2) "hi"
Cannot extract to "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...", destination directory is too long for filesystem
2008-05-01 07:06:04 +08:00
Extraction from phar "%stempmanifest1.phar.php" failed: Cannot extract "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." to "%s...", extracted filename is too long for filesystem
2008-08-01 21:36:19 +08:00
===DONE===