1--TEST-- 2Phar::setStub() 3--SKIPIF-- 4<?php if (!extension_loaded("phar")) die("skip"); ?> 5--INI-- 6phar.require_hash=0 7phar.readonly=0 8--FILE-- 9<?php 10$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; 11$pname = 'phar://' . $fname; 12$file = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>'; 13 14$files = array(); 15$files['a'] = 'a'; 16$files['b'] = 'b'; 17$files['c'] = 'c'; 18 19include 'files/phar_test.inc'; 20 21$file = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>'; 22$fp = fopen($fname, 'rb'); 23//// 1 24echo fread($fp, strlen($file)) . "\n"; 25fclose($fp); 26$phar = new Phar($fname); 27$file = '<?php echo "second stub\n"; __HALT_COMPILER(); ?>'; 28 29//// 2 30$phar->setStub($file); 31$fp = fopen($fname, 'rb'); 32echo fread($fp, strlen($file)) . "\n"; 33fclose($fp); 34 35$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phartmp.php'; 36$file = b'<?php echo "third stub\n"; __HALT_COMPILER(); ?>'; 37$fp = fopen($fname2, 'wb'); 38fwrite($fp, $file); 39fclose($fp); 40$fp = fopen($fname2, 'rb'); 41 42//// 3 43$phar->setStub($fp); 44fclose($fp); 45 46$fp = fopen($fname, 'rb'); 47echo fread($fp, strlen($file)) . "\n"; 48fclose($fp); 49 50$fp = fopen($fname2, 'ab'); 51fwrite($fp, b'booya'); 52fclose($fp); 53echo file_get_contents($fname2) . "\n"; 54 55$fp = fopen($fname2, 'rb'); 56 57//// 4 58$phar->setStub($fp, strlen($file)); 59fclose($fp); 60 61$fp = fopen($fname, 'rb'); 62echo fread($fp, strlen($file)) . "\n"; 63if (fread($fp, strlen('booya')) == 'booya') { 64 echo 'failed - copied booya'; 65} 66fclose($fp); 67$phar['testing'] = 'hi'; 68 69// ensure stub is not overwritten 70$fp = fopen($fname, 'rb'); 71echo fread($fp, strlen($file)) . "\n"; 72if (fread($fp, strlen('booya')) == 'booya') { 73 echo 'failed - copied booya'; 74} 75fclose($fp); 76 77?> 78===DONE=== 79--CLEAN-- 80<?php 81unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); 82unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php'); 83__HALT_COMPILER(); 84?> 85--EXPECT-- 86<?php echo "first stub\n"; __HALT_COMPILER(); ?> 87<?php echo "second stub\n"; __HALT_COMPILER(); ?> 88<?php echo "third stub\n"; __HALT_COMPILER(); ?> 89<?php echo "third stub\n"; __HALT_COMPILER(); ?>booya 90<?php echo "third stub\n"; __HALT_COMPILER(); ?> 91<?php echo "third stub\n"; __HALT_COMPILER(); ?> 92===DONE=== 93