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