--- /dev/null
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller.phar.tar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a['index.php'] = 'here is my index';
+$a->setStub('<?php
+Phar::webPhar();
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
--- /dev/null
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller10.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller10.phar.tar');
+$a['index.php'] = '<?php
+var_dump($_SERVER["PHP_SELF"]);
+var_dump($_SERVER["SCRIPT_NAME"]);
+var_dump($_SERVER["SCRIPT_FILENAME"]);
+var_dump($_SERVER["REQUEST_URI"]);
+var_dump($_SERVER["PHAR_PHP_SELF"]);
+var_dump($_SERVER["PHAR_SCRIPT_NAME"]);
+var_dump($_SERVER["PHAR_SCRIPT_FILENAME"]);
+var_dump($_SERVER["PHAR_REQUEST_URI"]);
+';
+$a->setStub('<?php
+Phar::mungServer(array("PHP_SELF", "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI", "OOPSIE"));
+Phar::webPhar();
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
--- /dev/null
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller11.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller11.phar.tar');
+$a['index.php'] = '<?php
+var_dump($_SERVER["PHP_SELF"]);
+var_dump($_SERVER["SCRIPT_NAME"]);
+var_dump($_SERVER["SCRIPT_FILENAME"]);
+var_dump($_SERVER["REQUEST_URI"]);
+var_dump($_SERVER["PHAR_PHP_SELF"]);
+var_dump($_SERVER["PHAR_SCRIPT_NAME"]);
+var_dump($_SERVER["PHAR_SCRIPT_FILENAME"]);
+var_dump($_SERVER["PHAR_REQUEST_URI"]);
+';
+$a->setStub('<?php
+Phar::mungServer(array(array(), "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI"));
+Phar::webPhar();
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
--- /dev/null
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller12.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller12.phar.tar');
+$a['index.php'] = '<?php
+var_dump($_SERVER["PHP_SELF"]);
+var_dump($_SERVER["SCRIPT_NAME"]);
+var_dump($_SERVER["SCRIPT_FILENAME"]);
+var_dump($_SERVER["REQUEST_URI"]);
+var_dump($_SERVER["PHAR_PHP_SELF"]);
+var_dump($_SERVER["PHAR_SCRIPT_NAME"]);
+var_dump($_SERVER["PHAR_SCRIPT_FILENAME"]);
+var_dump($_SERVER["PHAR_REQUEST_URI"]);
+';
+$a->setStub('<?php
+Phar::mungServer(array("PHP_SELF", "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI"));
+Phar::webPhar();
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
--- /dev/null
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller2.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller2.phar.tar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "a.php");
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
--- /dev/null
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller3.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller3.phar.tar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+function s($a)
+{
+ static $b = array("/hi" => "a.phps");
+ if (isset($b[$a])) return $b[$a];
+ return $a;
+}
+Phar::webPhar("whatever", "/index.php", null, array(), "s");
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
--- /dev/null
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller4.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller4.phar.tar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+function s($a)
+{
+ static $b = array("/hi" => false);
+ if (isset($b[$a])) return $b[$a];
+ return $a;
+}
+Phar::webPhar("whatever", "index.php", null, array(), "s");
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
--- /dev/null
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller5.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller5.phar.tar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array(0 => "oops"));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
--- /dev/null
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller6.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller6.phar.tar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array("blah" => 100));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
--- /dev/null
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller7.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller7.phar.tar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array("blah" => null));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
--- /dev/null
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller8.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller8.phar.tar');
+$a['a.phps'] = 'hio1';
+$a['a.jpg'] = 'hio2';
+$a['a.php'] = '<?php function hio(){}';
+$a['fronk.gronk'] = 'hio3';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array("jpg" => "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
--- /dev/null
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller9.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller9.phar.tar');
+$a['a.phps'] = 'hio1';
+$a['a.jpg'] = 'hio2';
+$a['a.php'] = '<?php function hio(){}';
+$a['fronk.gronk'] = 'hio3';
+$a->setStub('<?php
+Phar::mungServer(array());
+Phar::webPhar("whatever", "index.php", null, array("jpg" => "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
--- /dev/null
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+class corrupter extends tarmaker {
+function close()
+{
+ fwrite($this->tmp, 'oopsie');
+ fclose($this->tmp);
+}
+}
\ No newline at end of file
--- /dev/null
+<?php
+// stolen from PEAR2_Pyrus_Developer_Creator_Tar by Greg Beaver, the original author, for use in unit tests
+class tarmaker
+{
+ /**
+ * Path to archive file
+ *
+ * @var string
+ */
+ protected $archive;
+ /**
+ * Temporary stream used for creating the archive
+ *
+ * @var stream
+ */
+ protected $tmp;
+ protected $path;
+ protected $compress;
+ function __construct($path, $compress = 'zlib')
+ {
+ $this->compress = $compress;
+ if ($compress === 'bz2' && !function_exists('bzopen')) {
+ throw new PEAR2_Pyrus_Developer_Creator_Exception(
+ 'bzip2 extension not available');
+ }
+ if ($compress === 'zlib' && !function_exists('gzopen')) {
+ throw new PEAR2_Pyrus_Developer_Creator_Exception(
+ 'zlib extension not available');
+ }
+ $this->path = $path;
+ }
+
+ /**
+ * save a file inside this package
+ *
+ * This code is modified from Vincent Lascaux's File_Archive
+ * package, which is licensed under the LGPL license.
+ * @param string relative path within the package
+ * @param string|resource file contents or open file handle
+ */
+ function addFile($path, $fileOrStream, $stat = null)
+ {
+ clearstatcache();
+ if ($stat === null) {
+ if (is_resource($fileOrStream)) {
+ $stat = fstat($fileOrStream);
+ } else {
+ $stat = array(
+ 'mode' => 0x8000 + 0644,
+ 'uid' => 0,
+ 'gid' => 0,
+ 'size' => strlen($fileOrStream),
+ 'mtime' => time(),
+ );
+ }
+ }
+
+ $link = null;
+ if ($stat['mode'] & 0x4000) {
+ $type = 5; // Directory
+ } else if ($stat['mode'] & 0x8000) {
+ $type = 0; // Regular
+ } else if ($stat['mode'] & 0xA000) {
+ $type = 1; // Link
+ $link = @readlink($current);
+ } else {
+ $type = 9; // Unknown
+ }
+
+ $filePrefix = '';
+ if (strlen($path) > 255) {
+ throw new Exception(
+ "$path is too long, must be 255 characters or less"
+ );
+ } else if (strlen($path) > 100) {
+ $filePrefix = substr($path, 0, strlen($path)-100);
+ $path = substr($path, -100);
+ }
+
+ $block = pack('a100a8a8a8a12A12',
+ $path,
+ decoct($stat['mode']),
+ sprintf('%6s ',decoct($stat['uid'])),
+ sprintf('%6s ',decoct($stat['gid'])),
+ sprintf('%11s ',decoct($stat['size'])),
+ sprintf('%11s ',decoct($stat['mtime']))
+ );
+
+ $blockend = pack('a1a100a6a2a32a32a8a8a155a12',
+ $type,
+ $link,
+ 'ustar',
+ '00',
+ 'Pyrus',
+ 'Pyrus',
+ '',
+ '',
+ $filePrefix,
+ '');
+
+ $checkheader = array_merge(str_split($block), str_split($blockend));
+ if (!function_exists('_pear2tarchecksum')) {
+ function _pear2tarchecksum($a, $b) {return $a + ord($b);}
+ }
+ $checksum = 256; // 8 * ord(' ');
+ $checksum += array_reduce($checkheader, '_pear2tarchecksum');
+
+ $checksum = pack('a8', sprintf('%6s ', decoct($checksum)));
+
+ fwrite($this->tmp, $block . $checksum . $blockend, 512);
+ if (is_resource($fileOrStream)) {
+ stream_copy_to_stream($fileOrStream, $this->tmp);
+ if ($stat['size'] % 512) {
+ fwrite($this->tmp, str_repeat("\0", 512 - $stat['size'] % 512));
+ }
+ } else {
+ fwrite($this->tmp, $fileOrStream);
+ if (strlen($fileOrStream) % 512) {
+ fwrite($this->tmp, str_repeat("\0", 512 - strlen($fileOrStream) % 512));
+ }
+ }
+ }
+
+ /**
+ * Initialize the package creator
+ */
+ function init()
+ {
+ switch ($this->compress) {
+ case 'zlib' :
+ $this->tmp = gzopen($this->path, 'wb');
+ break;
+ case 'bz2' :
+ $this->tmp = bzopen($this->path, 'w');
+ break;
+ case 'none' :
+ $this->tmp = fopen($this->path, 'wb');
+ break;
+ default :
+ throw new Exception(
+ 'unknown compression type ' . $this->compress);
+ }
+ }
+
+ /**
+ * Create an internal directory, creating parent directories as needed
+ *
+ * @param string $dir
+ */
+ function mkdir($dir)
+ {
+ $this->addFile($dir, "", array(
+ 'mode' => 0x4000 + 0644,
+ 'uid' => 0,
+ 'gid' => 0,
+ 'size' => 0,
+ 'mtime' => time(),
+ ));
+ }
+
+ /**
+ * Finish saving the package
+ */
+ function close()
+ {
+ fwrite($this->tmp, pack('a1024', ''));
+ fclose($this->tmp);
+ }
+}
\ No newline at end of file