xref: /PHP-5.3/ext/phar/tests/phar_oo_008.phpt (revision 610c7fbe)
1--TEST--
2Phar object: iterating via SplFileObject
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
6--INI--
7phar.require_hash=0
8--FILE--
9<?php
10
11$pharconfig = 1;
12
13require_once 'files/phar_oo_test.inc';
14
15$phar = new Phar($fname);
16$phar->setInfoClass('SplFileObject');
17
18$f = $phar['a.csv'];
19echo "===1===\n";
20foreach($f as $k => $v)
21{
22	echo "$k=>$v\n";
23}
24
25$f->setFlags(SplFileObject::DROP_NEW_LINE);
26
27echo "===2===\n";
28foreach($f as $k => $v)
29{
30	echo "$k=>$v\n";
31}
32
33class MyCSVFile extends SplFileObject
34{
35	function current()
36	{
37		return parent::fgetcsv(',', '"');
38	}
39}
40
41$phar->setInfoClass('MyCSVFile');
42$v = $phar['a.csv'];
43
44echo "===3===\n";
45while(!$v->eof())
46{
47	echo $v->key() . "=>" . join('|',$v->fgetcsv()) . "\n";
48}
49
50echo "===4===\n";
51$v->rewind();
52while(!$v->eof())
53{
54	$l = $v->fgetcsv();
55	echo $v->key() . "=>" . join('|',$l) . "\n";
56}
57
58echo "===5===\n";
59foreach($v as $k => $d)
60{
61	echo "$k=>" . join('|',$d) . "\n";
62}
63
64class MyCSVFile2 extends SplFileObject
65{
66	function getCurrentLine()
67	{
68		echo __METHOD__ . "\n";
69		return parent::fgetcsv(',', '"');
70	}
71}
72
73$phar->setInfoClass('MyCSVFile2');
74$v = $phar['a.csv'];
75
76echo "===6===\n";
77foreach($v as $k => $d)
78{
79	echo "$k=>" . join('|',$d) . "\n";
80}
81
82?>
83===DONE===
84--CLEAN--
85<?php
86unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
87__halt_compiler();
88?>
89--EXPECTF--
90===1===
910=>1,2,3
92
931=>2,a,b
94
952=>3,"c","'e'"
96===2===
970=>1,2,3
981=>2,a,b
992=>3,"c","'e'"
100===3===
1010=>1|2|3
1020=>2|a|b
1031=>3|c|'e'
104===4===
1050=>1|2|3
1061=>2|a|b
1072=>3|c|'e'
108===5===
1090=>1|2|3
1101=>2|a|b
1112=>3|c|'e'
112===6===
113MyCSVFile2::getCurrentLine
1141=>1|2|3
115MyCSVFile2::getCurrentLine
1163=>2|a|b
117MyCSVFile2::getCurrentLine
1185=>3|c|'e'
119===DONE===
120