Add CSV file data source
[bdrem.git] / src / phar-stub.php
1 <?php
2 /**
3  * Phar stub file for bdrem. Handles startup of the .phar file.
4  *
5  * PHP version 5
6  *
7  * @category  Tools
8  * @package   Bdrem
9  * @author    Christian Weiske <cweiske@cweiske.de>
10  * @copyright 2014 Christian Weiske
11  * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12  * @link      http://cweiske.de/bdrem.htm
13  */
14 if (!in_array('phar', stream_get_wrappers()) || !class_exists('Phar', false)) {
15     echo "Phar extension not avaiable\n";
16     exit(255);
17 }
18
19 $web = 'www/index.php';
20 $cli = 'bin/phar-bdrem.php';
21
22 /**
23  * Rewrite the HTTP request path to an internal file.
24  * Maps "" and "/" to "www/index.php".
25  *
26  * @param string $path Path from the browser, relative to the .phar
27  *
28  * @return string Internal path.
29  */
30 function rewritePath($path)
31 {
32     if ($path == '' || $path == '/') {
33         return 'www/index.php';
34     }
35     return $path;
36 }
37
38 //Phar::interceptFileFuncs();
39 set_include_path(
40     'phar://' . __FILE__
41     . PATH_SEPARATOR . 'phar://' . __FILE__ . '/lib/'
42 );
43 Phar::webPhar(null, $web, null, array(), 'rewritePath');
44
45 //work around https://bugs.php.net/bug.php?id=52322
46 if (php_sapi_name() == 'cgi-fcgi') {
47     require 'phar://' . __FILE__ . '/' . $web;
48     exit();
49 }
50
51 require 'phar://' . __FILE__ . '/' . $cli;
52 __HALT_COMPILER();
53 ?>