xref: /PHP-7.3/ext/phar/tests/phar_oo_008.phpt (revision 17ccbeec)
1--TEST--
2Phar object: iterating via SplFileObject
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5--INI--
6phar.require_hash=0
7--FILE--
8<?php
9
10$pharconfig = 1;
11
12require_once 'files/phar_oo_test.inc';
13
14$phar = new Phar($fname);
15$phar->setInfoClass('SplFileObject');
16
17$f = $phar['a.csv'];
18echo "===1===\n";
19foreach($f as $k => $v)
20{
21	echo "$k=>$v\n";
22}
23
24$f->setFlags(SplFileObject::DROP_NEW_LINE);
25
26echo "===2===\n";
27foreach($f as $k => $v)
28{
29	echo "$k=>$v\n";
30}
31
32class MyCSVFile extends SplFileObject
33{
34	function current()
35	{
36		return parent::fgetcsv(',', '"');
37	}
38}
39
40$phar->setInfoClass('MyCSVFile');
41$v = $phar['a.csv'];
42
43echo "===3===\n";
44while(!$v->eof())
45{
46	echo $v->key() . "=>" . join('|',$v->fgetcsv()) . "\n";
47}
48
49echo "===4===\n";
50$v->rewind();
51while(!$v->eof())
52{
53	$l = $v->fgetcsv();
54	echo $v->key() . "=>" . join('|',$l) . "\n";
55}
56
57echo "===5===\n";
58foreach($v as $k => $d)
59{
60	echo "$k=>" . join('|',$d) . "\n";
61}
62
63class MyCSVFile2 extends SplFileObject
64{
65	function getCurrentLine()
66	{
67		echo __METHOD__ . "\n";
68		return parent::fgetcsv(',', '"');
69	}
70}
71
72$phar->setInfoClass('MyCSVFile2');
73$v = $phar['a.csv'];
74
75echo "===6===\n";
76foreach($v as $k => $d)
77{
78	echo "$k=>" . join('|',$d) . "\n";
79}
80
81?>
82===DONE===
83--CLEAN--
84<?php
85unlink(dirname(__FILE__) . '/files/phar_oo_008.phar.php');
86__halt_compiler();
87?>
88--EXPECT--
89===1===
900=>1,2,3
91
921=>2,a,b
93
942=>3,"c","'e'"
95===2===
960=>1,2,3
971=>2,a,b
982=>3,"c","'e'"
99===3===
1000=>1|2|3
1010=>2|a|b
1021=>3|c|'e'
103===4===
1040=>1|2|3
1051=>2|a|b
1062=>3|c|'e'
107===5===
1080=>1|2|3
1091=>2|a|b
1102=>3|c|'e'
111===6===
112MyCSVFile2::getCurrentLine
1131=>1|2|3
114MyCSVFile2::getCurrentLine
1153=>2|a|b
116MyCSVFile2::getCurrentLine
1175=>3|c|'e'
118===DONE===
119