1--TEST--
2Phar::startBuffering()/setStub()/stopBuffering() zip-based
3--EXTENSIONS--
4phar
5--INI--
6phar.readonly=0
7--FILE--
8<?php
9$p = new Phar(__DIR__ . '/phar_begin_setstub_commit.phar.zip', 0, 'phar_begin_setstub_commit.phar');
10var_dump($p->isFileFormat(Phar::ZIP));
11//var_dump($p->getStub());
12var_dump($p->isBuffering());
13$p->startBuffering();
14var_dump($p->isBuffering());
15$p['a.php'] = '<?php var_dump("Hello");';
16$p->setStub('<?php var_dump("First"); Phar::mapPhar("phar_begin_setstub_commit.phar"); __HALT_COMPILER(); ?>');
17include 'phar://phar_begin_setstub_commit.phar/a.php';
18var_dump($p->getStub());
19$p['b.php'] = '<?php var_dump("World");';
20$p->setStub('<?php var_dump("Second"); Phar::mapPhar("phar_begin_setstub_commit.phar"); __HALT_COMPILER();');
21include 'phar://phar_begin_setstub_commit.phar/b.php';
22var_dump($p->getStub());
23$p->stopBuffering();
24echo "===COMMIT===\n";
25var_dump($p->isBuffering());
26include 'phar://phar_begin_setstub_commit.phar/a.php';
27include 'phar://phar_begin_setstub_commit.phar/b.php';
28var_dump($p->getStub());
29
30// add portion to test setting stub from resource
31file_put_contents(__DIR__ . '/myfakestub.php', '<?php var_dump("First resource"); Phar::mapPhar("phar_begin_setstub_commit.phar"); __HALT_COMPILER(); ?>');
32$a = fopen(__DIR__ . '/myfakestub.php', 'rb');
33$p->setStub($a);
34var_dump($p->getStub());
35$c = strlen('<?php var_dump("First resource"); Phar::mapPhar("phar_begin_setstub_commit.phar"); __HALT_COMPILER(); ?>');
36file_put_contents(__DIR__ . '/myfakestub.php', '<?php var_dump("First resource"); Phar::mapPhar("phar_begin_setstub_commit.phar"); __HALT_COMPILER(); ?>' . 'extra stuff');
37fseek($a, 0);
38$p->setStub($a, $c);
39var_dump($p->getStub());
40fclose($a);
41?>
42--CLEAN--
43<?php
44unlink(__DIR__ . '/phar_begin_setstub_commit.phar.zip');
45unlink(__DIR__ . '/myfakestub.php');
46?>
47--EXPECTF--
48bool(true)
49bool(false)
50bool(true)
51string(5) "Hello"
52string(%d) "<?php var_dump("First"); Phar::mapPhar("phar_begin_setstub_commit.phar"); __HALT_COMPILER(); ?>
53"
54string(5) "World"
55string(%d) "<?php var_dump("Second"); Phar::mapPhar("phar_begin_setstub_commit.phar"); __HALT_COMPILER(); ?>
56"
57===COMMIT===
58bool(false)
59string(5) "Hello"
60string(5) "World"
61string(%d) "<?php var_dump("Second"); Phar::mapPhar("phar_begin_setstub_commit.phar"); __HALT_COMPILER(); ?>
62"
63
64Deprecated: Calling Phar::setStub(resource $stub, int $length) is deprecated in %s on line %d
65string(%d) "<?php var_dump("First resource"); Phar::mapPhar("phar_begin_setstub_commit.phar"); __HALT_COMPILER(); ?>
66"
67
68Deprecated: Calling Phar::setStub(resource $stub, int $length) is deprecated in %s on line %d
69string(%d) "<?php var_dump("First resource"); Phar::mapPhar("phar_begin_setstub_commit.phar"); __HALT_COMPILER(); ?>
70"
71